Hello,
Ive written a few C++ programs using devc, VC++. Looking to control 2
transistors and look at inputs from some buttons and sensors. Pretty simple
program. I'm looking for an example source code of a simple C++ program that
uses math.h etc. Mainly Im unsure how to reference the libraries, and how to
specify the c standard I'm using (-std=c++98?)Thanks
Justin
C++ examples
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: C++ examples
> Ive written a few C++ programs using devc, VC++. Looking to control 2
transistors and look at inputs from some buttons and sensors. Pretty simple
program. I'm looking for an example source code of a simple C++ program that
uses math.h etc. Mainly Im unsure how to reference the libraries, and how to
specify the c standard I'm using (-std=c++98?)
While the gcc compiler supports it, we haven't tried C++, but would expect it to
chew up a lot of the available memory of the ARMmite devices.
For C, the Csample.c will do all of the above.
You might query the gnuarm group about use of C++ on the LPC2103, or the LPC2000
group.
transistors and look at inputs from some buttons and sensors. Pretty simple
program. I'm looking for an example source code of a simple C++ program that
uses math.h etc. Mainly Im unsure how to reference the libraries, and how to
specify the c standard I'm using (-std=c++98?)
While the gcc compiler supports it, we haven't tried C++, but would expect it to
chew up a lot of the available memory of the ARMmite devices.
For C, the Csample.c will do all of the above.
You might query the gnuarm group about use of C++ on the LPC2103, or the LPC2000
group.
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: C++ examples
Thanks for the reply, I can just declare all of the variables globally for this
application. so the standard C will probably be fine. Here is the program
outline.
//Controller Program
//Justin Leighton 2009
//calculates ball speed using infrared distance sensor, controls two 5 amp
//outputs from 0 to 120 Volts based on rotor rpm.
//rotor rpm is read from hall effect sensor, simplifying the design
//declare libraries etc
//all global variables (security not an issue, 5-10 total variables
float Rotor_RPM[2];
float Rotor_PWM_Percent[2];
bool Increase_RPM_Button[2]; //user is pressing up arrow on rpm button, alters
current pitch
bool Decrease_RPM_Button[2]; //user is pressing up arrow on rpm button
bool Save_Pitch; //user saved pitch
bool Next_Pitch; //user pressed next pitch button
int Current_Pitch; //incremented with next pitch button
float Saved_Pitches[10][2]; //saves the PWM percent, used to save and load
curveballs etc
int Infrared_Sensor_Voltage_Level; //indicates if ball is in range, distance
bool Ball_launched; //set to true to initiate speed calc loop
int Ball_Distance_Array[10]; // stores ten ball distances on every ball launch
used to calculate //dv/dt of ball
float Ball_Distance_Rate_Of_Change;
const float Ball_Speed_Constant = .0025; //correlates dx/dt to ball velocity
int Last_Ball_Speed;
Bool Error_Found;
void Error_Check()
{
}//end function error check
void Button_Check() //checks for user input, sets boolean values
{
}//end button check
void Calculate_RPM()
{}
void Update_ADC()
{}
void Update_Infrared()
{}
Void Get_Ball_Speed()
{}
Update_LCD()
{}
void Main()
{
Error_Check();
Button_Check(); //get user button input, increment values
Calculate_RPM(); //look at hall sensors on rotors (ADC input to 8 bit int), get
rpms
Update_ADC(); //set pwm percent based on rpms
Update_Infrared();//Check for infrared sensor going HI
Get_Ball_Speed(); //if infrared goes HI, take accurate readings from ADC
Update_LCD(); //output current program vars to serial LCD at 9600 Baud
if (Error_Found == false)
{Main();} //loop
}// end main loop
I want to know what libraries, calls etc will be necessary to make this program
work on the c-stamp, there will be a few math loops to change PWM percent etc as
well.
application. so the standard C will probably be fine. Here is the program
outline.
//Controller Program
//Justin Leighton 2009
//calculates ball speed using infrared distance sensor, controls two 5 amp
//outputs from 0 to 120 Volts based on rotor rpm.
//rotor rpm is read from hall effect sensor, simplifying the design
//declare libraries etc
//all global variables (security not an issue, 5-10 total variables
float Rotor_RPM[2];
float Rotor_PWM_Percent[2];
bool Increase_RPM_Button[2]; //user is pressing up arrow on rpm button, alters
current pitch
bool Decrease_RPM_Button[2]; //user is pressing up arrow on rpm button
bool Save_Pitch; //user saved pitch
bool Next_Pitch; //user pressed next pitch button
int Current_Pitch; //incremented with next pitch button
float Saved_Pitches[10][2]; //saves the PWM percent, used to save and load
curveballs etc
int Infrared_Sensor_Voltage_Level; //indicates if ball is in range, distance
bool Ball_launched; //set to true to initiate speed calc loop
int Ball_Distance_Array[10]; // stores ten ball distances on every ball launch
used to calculate //dv/dt of ball
float Ball_Distance_Rate_Of_Change;
const float Ball_Speed_Constant = .0025; //correlates dx/dt to ball velocity
int Last_Ball_Speed;
Bool Error_Found;
void Error_Check()
{
}//end function error check
void Button_Check() //checks for user input, sets boolean values
{
}//end button check
void Calculate_RPM()
{}
void Update_ADC()
{}
void Update_Infrared()
{}
Void Get_Ball_Speed()
{}
Update_LCD()
{}
void Main()
{
Error_Check();
Button_Check(); //get user button input, increment values
Calculate_RPM(); //look at hall sensors on rotors (ADC input to 8 bit int), get
rpms
Update_ADC(); //set pwm percent based on rpms
Update_Infrared();//Check for infrared sensor going HI
Get_Ball_Speed(); //if infrared goes HI, take accurate readings from ADC
Update_LCD(); //output current program vars to serial LCD at 9600 Baud
if (Error_Found == false)
{Main();} //loop
}// end main loop
I want to know what libraries, calls etc will be necessary to make this program
work on the c-stamp, there will be a few math loops to change PWM percent etc as
well.
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: C++ examples
Since this discussion, the MakeItC utility now supports Sketches, which means it also supports C++
We have at least supplied the startup and environment needed for C++ programs, but we here are not C++ programmers, though that has never stopped us from hacking on something.
As they say if it ain't broke hit it with a hammer, or something like that
We have at least supplied the startup and environment needed for C++ programs, but we here are not C++ programmers, though that has never stopped us from hacking on something.
As they say if it ain't broke hit it with a hammer, or something like that