Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int ButtonOne = A0; // input pin one
- int ButtonTwo = A1; // input pin two
- int ButtonThree = A2; // input pin three
- int ButtonFour = A3; // input pin four
- int ButtonOneValue = 0; // variable to store button one instantaneous state
- int ButtonTwoValue = 0; // variable to store button two instantaneous state
- int ButtonThreeValue = 0; // variable to store button three instantaneous state
- int ButtonFourValue = 0; // variable to store button three instantaneous state
- int LEDOnePin = 9; // select the pin for the first LED strip
- int LEDTwoPin = 10; // select the pin for the second LED strip
- int LEDThreePin = 11; // select the pin for the third LED strip
- int LEDOneState = 0; // variable to store the state of LED one
- int LEDTwoState = 0; // variable to store the state of LED two
- int LEDThreeState = 0; // variable to store the state of LED three
- int counter = 0; //test variable
- void setup() {
- Serial.begin(9600); // setup serial
- // declare the LED pins as an OUTPUT:
- pinMode(LEDOnePin, OUTPUT);
- pinMode(LEDTwoPin, OUTPUT);
- pinMode(LEDThreePin, OUTPUT);
- pinMode(13, OUTPUT);
- // turn the LED pins off:
- digitalWrite(LEDOnePin, LOW);
- digitalWrite(LEDTwoPin, LOW);
- digitalWrite(LEDThreePin, LOW);
- }
- void loop() {
- // read the value from the input pins:
- ButtonOneValue = analogRead(ButtonOne);
- ButtonTwoValue = analogRead(ButtonTwo);
- ButtonThreeValue = analogRead(ButtonThree);
- ButtonFourValue = analogRead(ButtonFour);
- //delay 100ms to process input selection (fingers leaving buttons)
- delay(200);
- counter = counter + 1;
- Serial.println(counter); // debug value
- // set output pin states
- //do something only if there is an input
- if ((ButtonOneValue > 1000) || (ButtonTwoValue > 1000) || (ButtonThreeValue > 1000) || (ButtonFourValue > 1000)){
- // turn the led pin ON if input pin is HIGH / 5V and OFF if input is LOW / 0V
- if(ButtonOneValue > 1000)
- {
- //Serial.println(ButtonOneValue); // debug value
- LEDOneOn();
- }else{
- LEDOneOff();
- }
- if(ButtonTwoValue > 1000)
- {
- LEDTwoOn();
- }else{
- LEDTwoOff();
- }
- if(ButtonThreeValue > 1000)
- {
- LEDThreeOn();
- }else{
- LEDThreeOff();
- }
- if(ButtonFourValue > 1000){
- }
- }
- }
- void LEDOneOn(){
- digitalWrite(LEDOnePin, HIGH);
- LEDOneState=1;
- }
- void LEDTwoOn(){
- digitalWrite(LEDTwoPin, HIGH);
- LEDTwoState=1;
- }
- void LEDThreeOn(){
- digitalWrite(LEDThreePin, HIGH);
- LEDThreeState=1;
- }
- void LEDOneOff(){
- digitalWrite(LEDOnePin, LOW);
- LEDOneState=0;
- }
- void LEDTwoOff(){
- digitalWrite(LEDTwoPin, LOW);
- LEDTwoState=0;
- }
- void LEDThreeOff(){
- digitalWrite(LEDThreePin, LOW);
- LEDThreeState=0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement