SHARE
TWEET

Stigern

a guest Oct 30th, 2009 1,031 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int ledPin1 =  3;
  2. int ledPin2 =  4;
  3. int ledPin3 =  5;
  4. int ledPin4 =  6;
  5. int ledPin5 =  7;
  6. int ledPin6 =  8;
  7. int ledPin7 =  9;
  8. int ledPin8 =  10;
  9. int ledPin9 =  11;
  10.  
  11.  
  12. void setup()
  13. {
  14.   Serial.begin(9600);
  15.   // Define the led pins as outputs
  16.   pinMode(ledPin1, OUTPUT);
  17.   pinMode(ledPin2, OUTPUT);
  18.   pinMode(ledPin3, OUTPUT);
  19.   pinMode(ledPin4, OUTPUT);
  20.   pinMode(ledPin5, OUTPUT);
  21.   pinMode(ledPin6, OUTPUT);
  22.   pinMode(ledPin7, OUTPUT);
  23.   pinMode(ledPin8, OUTPUT);
  24.   pinMode(ledPin9, OUTPUT);
  25. }
  26.  
  27. void loop()
  28. {
  29.  
  30.   // Read data from serial communication
  31.   if (Serial.available() > 0) {
  32.     int b = Serial.read();
  33.  
  34.     // Note, I made it so that it's more sensitive to 0-40% load.
  35.     // Since thats where it's usually at when using the computer as normal.
  36.     if (b > 0 && b < 5)
  37.     {
  38.       digitalWrite(ledPin1, HIGH);
  39.       digitalWrite(ledPin2, LOW);
  40.       digitalWrite(ledPin3, LOW);
  41.       digitalWrite(ledPin4, LOW);
  42.       digitalWrite(ledPin5, LOW);
  43.       digitalWrite(ledPin6, LOW);
  44.       digitalWrite(ledPin7, LOW);
  45.       digitalWrite(ledPin8, LOW);
  46.       digitalWrite(ledPin9, LOW);
  47.     }
  48.     if (b > 5 && b < 10)
  49.     {
  50.       digitalWrite(ledPin1, HIGH);
  51.       digitalWrite(ledPin2, HIGH);
  52.       digitalWrite(ledPin3, LOW);
  53.       digitalWrite(ledPin4, LOW);
  54.       digitalWrite(ledPin5, LOW);
  55.       digitalWrite(ledPin6, LOW);
  56.       digitalWrite(ledPin7, LOW);
  57.       digitalWrite(ledPin8, LOW);
  58.       digitalWrite(ledPin9, LOW);
  59.     }
  60.     if (b > 10 && b < 15)
  61.     {
  62.       digitalWrite(ledPin1, HIGH);
  63.       digitalWrite(ledPin2, HIGH);
  64.       digitalWrite(ledPin3, HIGH);
  65.       digitalWrite(ledPin4, LOW);
  66.       digitalWrite(ledPin5, LOW);
  67.       digitalWrite(ledPin6, LOW);
  68.       digitalWrite(ledPin7, LOW);
  69.       digitalWrite(ledPin8, LOW);
  70.       digitalWrite(ledPin9, LOW);
  71.     }
  72.     if (b > 15 && b < 20)
  73.     {
  74.       digitalWrite(ledPin1, HIGH);
  75.       digitalWrite(ledPin2, HIGH);
  76.       digitalWrite(ledPin3, HIGH);
  77.       digitalWrite(ledPin4, HIGH);
  78.       digitalWrite(ledPin5, LOW);
  79.       digitalWrite(ledPin6, LOW);
  80.       digitalWrite(ledPin7, LOW);
  81.       digitalWrite(ledPin8, LOW);
  82.       digitalWrite(ledPin9, LOW);
  83.     }
  84.     if (b > 25 && b < 30)
  85.     {
  86.       digitalWrite(ledPin1, HIGH);
  87.       digitalWrite(ledPin2, HIGH);
  88.       digitalWrite(ledPin3, HIGH);
  89.       digitalWrite(ledPin4, HIGH);
  90.       digitalWrite(ledPin5, HIGH);
  91.       digitalWrite(ledPin6, LOW);
  92.       digitalWrite(ledPin7, LOW);
  93.       digitalWrite(ledPin8, LOW);
  94.       digitalWrite(ledPin9, LOW);
  95.     }
  96.     if (b > 35 && b < 40)
  97.     {
  98.       digitalWrite(ledPin1, HIGH);
  99.       digitalWrite(ledPin2, HIGH);
  100.       digitalWrite(ledPin3, HIGH);
  101.       digitalWrite(ledPin4, HIGH);
  102.       digitalWrite(ledPin5, HIGH);
  103.       digitalWrite(ledPin6, HIGH);
  104.       digitalWrite(ledPin7, LOW);
  105.       digitalWrite(ledPin8, LOW);
  106.       digitalWrite(ledPin9, LOW);
  107.     }
  108.     if (b > 40 && b < 60)
  109.     {
  110.       digitalWrite(ledPin1, HIGH);
  111.       digitalWrite(ledPin2, HIGH);
  112.       digitalWrite(ledPin3, HIGH);
  113.       digitalWrite(ledPin4, HIGH);
  114.       digitalWrite(ledPin5, HIGH);
  115.       digitalWrite(ledPin6, HIGH);
  116.       digitalWrite(ledPin7, HIGH);
  117.       digitalWrite(ledPin8, LOW);
  118.       digitalWrite(ledPin9, LOW);
  119.     }
  120.     if (b > 60 && b < 80)
  121.     {
  122.       digitalWrite(ledPin1, HIGH);
  123.       digitalWrite(ledPin2, HIGH);
  124.       digitalWrite(ledPin3, HIGH);
  125.       digitalWrite(ledPin4, HIGH);
  126.       digitalWrite(ledPin5, HIGH);
  127.       digitalWrite(ledPin6, HIGH);
  128.       digitalWrite(ledPin7, HIGH);
  129.       digitalWrite(ledPin8, HIGH);
  130.       digitalWrite(ledPin9, LOW);
  131.     }
  132.     if (b > 80 && b < 100)
  133.     {
  134.       digitalWrite(ledPin1, HIGH);
  135.       digitalWrite(ledPin2, HIGH);
  136.       digitalWrite(ledPin3, HIGH);
  137.       digitalWrite(ledPin4, HIGH);
  138.       digitalWrite(ledPin5, HIGH);
  139.       digitalWrite(ledPin6, HIGH);
  140.       digitalWrite(ledPin7, HIGH);
  141.       digitalWrite(ledPin8, HIGH);
  142.       digitalWrite(ledPin9, HIGH);
  143.     }
  144.     Serial.flush();
  145.   }
  146. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top