Advertisement
andrewb

blink3.ino

Apr 25th, 2014
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. /*****
  2.  * blink3.ino
  3.  * Blinks the number of times you type in the Serial Monitor.
  4.  * Runs on: Arduino Uno rev3
  5.  * Created by: Andrew Burton
  6.  *****/
  7.  
  8. String count = "";
  9. int yesno = 0;
  10. int led = 13;
  11.  
  12. void setup() {
  13.   Serial.begin(9600);
  14.   pinMode(led, OUTPUT);
  15.   digitalWrite(led, LOW);
  16. }
  17.  
  18. void loop() {
  19.   if (Serial.available() > 0) {
  20.     yesno = 1;
  21.     char c = Serial.read();
  22.     count = count + c;
  23.   } else {
  24.     if (yesno == 1) {
  25.       int cnt = count.toInt();
  26.       if (cnt > 0) {
  27.         Serial.println("Print " + count + " times.");
  28.         Blinker(cnt);
  29.       }
  30.       count = "";
  31.       yesno = 0;
  32.     }
  33.   }
  34.   delay(100);
  35. }
  36.  
  37. void Blinker(int times) {
  38.   delay(100);
  39.   for (int x = 0; x < times; x++) {
  40.     digitalWrite(led, HIGH);
  41.     delay(500);
  42.     digitalWrite(led, LOW);
  43.     delay(500);
  44.   }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement