SonicDH

WiCuBoBS - Slave

Apr 17th, 2012
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. int ledPins[] = { 13, 12, 11, 10, 7, 6, 5, 4, 3, 2 };
  2. int pinCount = 10;
  3. void setup()
  4. {
  5.   int thisPin;
  6.   for (int thisPin = 0; thisPin < pinCount; thisPin++)  {
  7.     pinMode(ledPins[thisPin], OUTPUT);      
  8.   }
  9.   Serial.begin(57600);
  10.   Serial.println("You know what to do.");
  11. }
  12. void loop() {  
  13.   static int val = 0;
  14.   if (Serial.available())
  15.   {
  16.     int ch = Serial.read();
  17.     switch(ch)
  18.     {
  19.       case '1'...'9':
  20.         val = ch - '0';
  21.         Serial.println(val);
  22.         for (int thisPin = 0; thisPin < val; thisPin++) {
  23.         // turn the pin on:
  24.         digitalWrite(ledPins[thisPin], HIGH);}
  25.         delay(1000);
  26.         for (int thisPin = val - 1; thisPin >= 0; thisPin--) {
  27.         // turn the pin off:
  28.         digitalWrite(ledPins[thisPin], LOW);
  29.         delay(1000);}
  30.         flash();
  31.         break;
  32.       case 'x':
  33.         Serial.println(10);
  34.         for (int thisPin = 0; thisPin < 10; thisPin++) {
  35.         digitalWrite(ledPins[thisPin], HIGH);}
  36.         delay(1000);
  37.         for (int thisPin = 10 - 1; thisPin >= 0; thisPin--) {
  38.         digitalWrite(ledPins[thisPin], LOW);
  39.         delay(1000);}
  40.         flash();
  41.         break;
  42.       case '0':
  43.         Serial.println("NOW");
  44.         flash();
  45.     }
  46.  }
  47. val = 0;
  48. }
  49. void flash(){
  50.   for (int i=0; i <= 3; i++){
  51.         for (int thisPin = 0; thisPin < 10; thisPin++) {
  52.         digitalWrite(ledPins[thisPin], HIGH);}
  53.         delay(50);
  54.         for (int thisPin = 10 - 1; thisPin >= 0; thisPin--) {
  55.         digitalWrite(ledPins[thisPin], LOW);}
  56.         delay(50);}
  57. }
Advertisement
Add Comment
Please, Sign In to add comment