Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // counter button w/ different outcomes with different number of button presses
- // Nikitha Thoduguli
- // 12.05.19
- // Ver 3
- int ledPin=8;
- int ledPin2=10;
- int buttonPin=2;
- int readValue;
- int count = 0;
- void setup() {
- // put your setup code here, to run once:
- pinMode (buttonPin, INPUT);
- pinMode (ledPin, OUTPUT);
- pinMode (ledPin2, OUTPUT);
- Serial.begin (9600);
- digitalWrite (ledPin, HIGH);
- digitalWrite (ledPin2, HIGH);
- delay (100);
- digitalWrite (ledPin2, LOW);
- digitalWrite (ledPin, LOW);
- Serial.println (readValue);
- delay (100);
- }
- void loop() {
- readValue = digitalRead (buttonPin);
- delay(100);
- if (readValue ==1)
- {
- count ++;
- Serial.println (count);
- }
- if (count == 1)
- {
- digitalWrite (ledPin, HIGH);
- digitalWrite (ledPin2, LOW);
- }
- if (count ==2 )
- {
- digitalWrite (ledPin, LOW);
- digitalWrite (ledPin2, HIGH);
- }
- if (count ==3)
- {
- digitalWrite (ledPin, HIGH);
- digitalWrite (ledPin2, HIGH);
- }
- if (count ==4)
- {
- digitalWrite (ledPin, LOW);
- digitalWrite (ledPin2, LOW);
- count = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement