51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
/*
|
|
IntegerInput_FloatOutput by m. Ray Burnette - PUBLIC DOMAIN EXAMPLE
|
|
Maple Mini: Compiled under Arduino 1.6.0rc1
|
|
Sketch uses 19,868 bytes (18%) of program storage space. Maximum is 108,000 bytes.
|
|
Global variables use 3,704 bytes of dynamic memory.
|
|
*/
|
|
|
|
#define BAUD 9600
|
|
#define timeoutPeriod 2147483647 // Long var... about 25 days
|
|
|
|
float a;
|
|
float b;
|
|
|
|
|
|
void setup()
|
|
{
|
|
// initialize the digital pin as an output.
|
|
pinMode(BOARD_LED_PIN, OUTPUT);
|
|
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
|
|
Serial.setTimeout(timeoutPeriod); // default is 1 second
|
|
// wait for serial monitor to be connected.
|
|
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
|
|
{
|
|
toggleLED();
|
|
delay(100); // fast blink
|
|
}
|
|
Serial.println("Integer Input - Floating Output");
|
|
Serial.println("You may wish to try 355 and 113 (Pi)");
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
Serial.println("Enter first integer: ");
|
|
|
|
a = Serial.parseInt();
|
|
Serial.print("a = ");
|
|
Serial.println(a);
|
|
|
|
Serial.println("Enter second integer: ");
|
|
|
|
b = Serial.parseInt();
|
|
Serial.print("b = ");
|
|
Serial.println(b);
|
|
|
|
a = a / b;
|
|
Serial.print( "a/b = ");
|
|
Serial.println(a);
|
|
Serial.println();
|
|
}
|
|
|