Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * getInt.cpp
- * Converts numerical string into an integer
- *
- * Author: Marcelo Shiniti Uchimura
- * When: Jan '09
- */
- byte incomingByte = 0; // for incoming serial data
- int value = 0; // for storing the input decimal value
- void setup() {
- Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
- }
- void loop() {
- // send data only when you receive data:
- if (Serial.available() > 0) {
- // read the incoming byte:
- incomingByte = Serial.read();
- if(incomingByte == 13) {
- Serial.println();
- Serial.println(value, DEC);
- value = 0;
- }
- else
- value = value * 10 + incomingByte - 0x30;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement