blink blink! – week 1 Pcomp
the exercise is about two things:
- adding a digital input to adruino
- adding a digital output to adruino
what is digital?
- when something has only two states..e.g. on/off…1/0
what could be a digital input?
-example: a switch
what could be a digital output?
- an LED which could go on or off
first, i want to just think about the switch. – - using a push button to control an adruino
The principle is simple. You have this pin 2, supply it with a high Voltage, it reads high (and the LED on pin13 on the adruino turns on as a result and proof! ); supply with low V (i.e. ground), it reads low (and the little LED won’t turn on)
so how do we use a switch to achieve the alternate states?
how to supply with high V? Connect to 5V on the adruino.
how to supply a low V? connect to ground.
How to control this? connect a pushbutton in between 5V and pin 2.
BUT
when the switch is closed, pin 2 now won’t actually go to 5V, it will actually go to ground becoz it is an easier way out…(everybody always wants an easier way out….)
and this will set the adruino on fire
to avoid this happening, we put a 10k resistor in between switch and ground
then i used the example code for Button Switch.
so this has worked. I then want to use my own LED, not the one that came with the Adruino.
so that will involve putting an LED on any pin other than pin2..say pin 13 (as a cliche)…putting an LED on pin 13 means putting it between pin 13 and ground.
well this is pretty much the same as the one above… how to make it more interesting?
well the people who wrote the Lab session already thought about it — adding another LED!
and controlling the two with not only switches but codes!
basically the goal is that when switch is closed, turn one LED on, and turn the other off.
the code is pretty simple…all we need to know is digitalWrite —> which is controlling digital output..
i modified the button switch code to make the LEDs on pin 9 and pin 10 blink alternatively.
my special switch?
my hair!
interesting accident happened…i disconnected the two wires that were connected to the switch, so they are in the air, and just by flipping my hair around, the LED blinks haaaaaa!