Papermind

simpan lebih dari 255 di EEPROM

Feb 1st, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.   String to Integer conversion
  3.  
  4.  Reads a serial input string until it sees a newline, then converts
  5.  the string to a number if the characters are digits.
  6.  
  7.  The circuit:
  8.  No external components needed.
  9.  
  10.  created 29 Nov 2010
  11.  by Tom Igoe
  12.  
  13.  This example code is in the public domain.
  14.  */
  15.  
  16. #include  <EEPROM.h>
  17.  
  18. String inString = "";    // string to hold input
  19. int formula;
  20.  
  21. void setup() {  Serial.begin(9600); }
  22.  
  23. void loop() {
  24.  
  25.   // Read serial input:
  26.   while (Serial.available() > 0) {
  27.     int inChar = Serial.read();
  28.     if (isDigit(inChar)) { inString += (char)inChar; }
  29.     if (inChar == '\n') {
  30.       Serial.print("Value:");
  31.       int val = inString.toInt();
  32.       if (val > 255 && val < 510) {
  33.         EEPROM.update(10, val/2);
  34.         EEPROM.update(11, val/2);
  35.         delay(200);
  36.         Serial.println(EEPROM.read(10) + EEPROM.read(11)+ val%2);
  37.         inString = "";
  38.       }
  39.       inString = "";
  40.     }
  41.   }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment