Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 5th, 2012  |  syntax: None  |  size: 3.46 KB  |  views: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. int led1 = 2;
  2. int led2 = A1;
  3. int led3 = A2;
  4. int led4 = A3;
  5. int led5 = A4;
  6. int led6 = A5;
  7.  
  8. int button1 = 0;
  9. int button2 = 0;
  10. int dh =1;
  11.  
  12. const int transistorPin = 9;    // connected to the base of the transistor
  13.  
  14.  
  15.  
  16. void setup(void)
  17. {
  18.   Serial.begin(9600);
  19.  
  20.   // set  the transistor pin as output:
  21.   pinMode(transistorPin, OUTPUT);
  22.  
  23.   pinMode(led1, OUTPUT);
  24.   pinMode(led2, OUTPUT);
  25.   pinMode(led3, OUTPUT);
  26.   pinMode(led4, OUTPUT);
  27.   pinMode(led5, OUTPUT);
  28.   pinMode(led6, OUTPUT);
  29.  
  30.   pinMode(5, OUTPUT);
  31.   pinMode(6, OUTPUT);
  32.   pinMode(3, INPUT);
  33.   pinMode(10, INPUT);
  34. }
  35.  
  36.  
  37. void loop(void){
  38.  
  39.   // read the potentiometer:
  40.   int sensorValue = analogRead(A0);
  41.   // map the sensor value to a range from 0 - 255:
  42.   int outputValue = map(sensorValue, 0, 1023, 0, 255);
  43.   // use that to control the transistor:
  44.   analogWrite(transistorPin, outputValue);
  45.  
  46.   while (dh=1){
  47.     // begin LEDs
  48.  
  49.     digitalWrite(led1, HIGH);
  50.     delay(100);
  51.     // read the potentiometer:
  52.     int sensorValue = analogRead(A0);
  53.     // map the sensor value to a range from 0 - 255:
  54.     int outputValue = map(sensorValue, 0, 1023, 0, 255);
  55.     // use that to control the transistor:
  56.     analogWrite(transistorPin, outputValue);
  57.     digitalWrite(led1, LOW);
  58.     delay(100);
  59.     digitalWrite(led2, HIGH);
  60.     delay(100);
  61.     digitalWrite(led2, LOW);
  62.     delay(100);
  63.     digitalWrite(led3, HIGH);
  64.     delay(100);
  65.     // read the potentiometer:
  66.  
  67.     // map the sensor value to a range from 0 - 255:
  68.  
  69.     // use that to control the transistor:
  70.     analogWrite(transistorPin, outputValue);
  71.     digitalWrite(led3, LOW);
  72.     delay(100);
  73.     digitalWrite(led4, HIGH);
  74.     delay(100);
  75.     digitalWrite(led4, LOW);
  76.     delay(100);
  77.     digitalWrite(led5, HIGH);
  78.     delay(100);
  79.     // read the potentiometer:
  80.  
  81.     // map the sensor value to a range from 0 - 255:
  82.  
  83.     // use that to control the transistor:
  84.     analogWrite(transistorPin, outputValue);
  85.     digitalWrite(led5, LOW);
  86.     delay(100);
  87.     digitalWrite(led6, HIGH);
  88.     delay(100);
  89.     digitalWrite(led6, LOW);
  90.     delay(100);
  91.  
  92.     // backwards LEDs  
  93.  
  94.     digitalWrite(3, HIGH);
  95.     digitalWrite(10, HIGH);
  96.  
  97.     // read the potentiometer:
  98.  
  99.     // map the sensor value to a range from 0 - 255:
  100.  
  101.     // use that to control the transistor:
  102.     analogWrite(transistorPin, outputValue);  
  103.     digitalWrite(led5, HIGH);
  104.     delay(100);
  105.     digitalWrite(led5, LOW);
  106.     delay(100);
  107.     // read the potentiometer:
  108.  
  109.     // map the sensor value to a range from 0 - 255:
  110.  
  111.     // use that to control the transistor:
  112.     analogWrite(transistorPin, outputValue);
  113.     digitalWrite(led4, HIGH);
  114.     delay(100);
  115.     digitalWrite(led4, LOW);
  116.     delay(100);
  117.     digitalWrite(led3, HIGH);
  118.     delay(100);
  119.     // read the potentiometer:
  120.  
  121.     // map the sensor value to a range from 0 - 255:
  122.  
  123.     // use that to control the transistor:
  124.     analogWrite(transistorPin, outputValue);
  125.     digitalWrite(led3, LOW);
  126.     delay(100);
  127.     digitalWrite(led2, HIGH);
  128.     delay(100);
  129.     digitalWrite(led2, LOW);
  130.     delay(100);
  131.     digitalWrite(led1, HIGH);
  132.  
  133.     digitalWrite(led1, LOW);
  134.  
  135.  
  136.     // end LEDs
  137.   }
  138.   while (dh=1){
  139.     button1 = digitalRead(3);
  140.     button2 = digitalRead(10);
  141.     if (button1 == LOW) {
  142.       digitalWrite(5, HIGH);
  143.       while(1);
  144.       while(1) {
  145.       }
  146.     }
  147.     if (button2 == LOW) {
  148.       digitalWrite(6, HIGH);
  149.       while(1);
  150.       while(1) {
  151.       }
  152.     }
  153.  
  154.   }
  155. }