Created
December 14, 2011 02:05
-
-
Save codejoust/1474896 to your computer and use it in GitHub Desktop.
Char Test Reader (Arduino C)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Arduino Char -> Number over serial. For testing, etc. | |
// @author Iain Nash iain.in | |
// @date 12/13/11 | |
//#define PWM_DEMO 1 | |
// ^ uncomment for pwm demo | |
#define PWM_DEMO 0 | |
// ^ and comment this | |
int get_serial_num(){ | |
int out = 0, i = 0, in; | |
while(true){ | |
in = Serial.read(); | |
if (in > 0 && in > 47 && in < 58){ | |
out += ((in - 48) * (pow(10, Serial.available()))); | |
} else { break; } | |
i++; | |
} | |
return out; | |
} | |
void setup(){ | |
Serial.begin(9600); | |
if (PWM_DEMO){ | |
pinMode(3, OUTPUT); | |
} else { | |
pinMode(13, OUTPUT); | |
} | |
} | |
void loop(){ | |
if (Serial.available()){ | |
if (PWM_DEMO){ | |
analogWrite(3, get_serial_num()); | |
} else { | |
digitalWrite(13, HIGH); | |
delay(get_serial_num()); | |
digitalWrite(13, LOW); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment