push button with led matrix

17
Demonstrating multi- dimensional array using 9 LEDs

Transcript of push button with led matrix

Page 1: push button with led matrix

Demonstrating multi-dimensional array using 9 LEDs

Page 2: push button with led matrix

You will need...

• Arduino Board (UNO)• 9 LEDs• 9 Resistors - 220Ω• Jumper Wires• Breadboard

Page 3: push button with led matrix

Declaring, Initializing and Referencing a matrix:

Page 4: push button with led matrix
Page 5: push button with led matrix

Program

int pinMatrix[3][3]=5,6,7,8,9,10,11,12,13;void setup() for(int i=0;i<3;i++) for(int j=0;j<3;j++) pinMode(pinMatrix[i][j],OUTPUT);

Page 6: push button with led matrix

Cont…void loop() for(int i=0;i<3;i++) for(int j=0;j<3;j++) digitalWrite(pinMatrix[i][j],HIGH); delay(20); digitalWrite(pinMatrix[i][j],LOW);

Page 7: push button with led matrix
Page 8: push button with led matrix
Page 9: push button with led matrix

working with push buttons

Page 10: push button with led matrix

Switch vs Push button

A "switch" is a binary device with an "on" and "off" position.You can toggle it between on and off positions.Can be implemented to on switch on and off an led manually. A "button" is a binary device with a momentary "on" position ,and reverts back to “off" position immediately. It cannot be toggled, but pushed multiple times.Can be implemented to count the number of votes ,increase the brightness of led manually.

Page 11: push button with led matrix

Connections

Page 12: push button with led matrix

Cont…Botton:•Leave 2 terminals open•One of the terminal to 5v•second terminal to 1k resistor and ground•Other terminal of resistor to arduino digital pinLed:•anode to ground•Cathode to arduino digital pin through 220 ohm resistor

Page 13: push button with led matrix

Switch on a LEDint ledPin=8;int pbPin=7; int val=0; void setup() pinMode(ledPin,OUTPUT); pinMode(pbPin,INPUT); void loop() val= digitalRead(pbPin); if (val==HIGH) digitalWrite(ledPin,HIGH); else digitalWrite(ledPin,LOW);

Page 14: push button with led matrix

To count no of button pressesint pbPin=7; int count=0;void setup() pinMode(pbPin,INPUT); Serial.begin(9600);void loop() if (digitalRead(pbPin)==HIGH) count++; Serial.print("students present="); Serial.print(count); Serial.print("\n"); else ;

Page 15: push button with led matrix

Problem encountered

For a single button press based on the duration ,the output will be as shown.

Page 16: push button with led matrix

Modified codeint count=0;int lastState=LOW;void setup() Serial.begin(9600); pinMode(7,INPUT); void loop() if(digitalRead(7)==HIGH&&lastState==LOW) count++; Serial.print("students present="); Serial.print(count); Serial.print("\n"); lastState=digitalRead(7);

Page 17: push button with led matrix

Output for 19 button presses.