Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- String to Integer conversion
- Reads a serial input string until it sees a newline, then converts
- the string to a number if the characters are digits.
- The circuit:
- No external components needed.
- created 29 Nov 2010
- by Tom Igoe
- This example code is in the public domain.
- */
- #include <EEPROM.h>
- String inString = ""; // string to hold input
- int formula;
- void setup() { Serial.begin(9600); }
- void loop() {
- // Read serial input:
- while (Serial.available() > 0) {
- int inChar = Serial.read();
- if (isDigit(inChar)) { inString += (char)inChar; }
- if (inChar == '\n') {
- Serial.print("Value:");
- int val = inString.toInt();
- if (val > 255 && val < 510) {
- EEPROM.update(10, val/2);
- EEPROM.update(11, val/2);
- delay(200);
- Serial.println(EEPROM.read(10) + EEPROM.read(11)+ val%2);
- inString = "";
- }
- inString = "";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment