United kingdom
Offline
Full Member
Karma: 0
Posts: 102
just think how much free time you would have if everything worked first time!!
|
 |
« on: February 01, 2012, 01:18:17 pm » |
I'm no electronics wizard, so the solution to this is probably very simple....
I have a tactile switch, I have wired this in series with a resistor and LED to a digital pin configured as output. When I write the the digital output the LED does not light until I depress the tactile switch. This works, its clear to me why and I understand it.
Then I wired the tactile switch to a digital pin configured as input. Another pin is configured as output with a resistor and LED connected.
In the code I read the digital input and if its HIGH set the digital output HIGH, if not I set the digital output LOW. This doesn't work and I'm struggling to see why not. The wiring for this is as follows:
(+) from pin 8 (configured as input) to one side of switch. (-) from other side of switch connected to GND. (+) from pin 13 (configured as output) to resistor, other side of resistor to longer leg of LED, short leg of LED connected to GND.
I'm trying to write a debounce routine using my timer libary, but failing to see why this doesn't work.
|
|
|
|
|
Logged
|
Kind Regards, Sy
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 249
Posts: 16544
Available for Design & Build services
|
 |
« Reply #1 on: February 01, 2012, 01:21:43 pm » |
Did you turn on the internal pullup resistor so the input pins sits a solid high level when switch is not pressed?
pinMode (pin8, INPUT); digitalWrite (pin8, HIGH);
|
|
|
|
|
Logged
|
|
|
|
|
United kingdom
Offline
Full Member
Karma: 0
Posts: 102
just think how much free time you would have if everything worked first time!!
|
 |
« Reply #2 on: February 01, 2012, 01:29:26 pm » |
No...I'm really confused and experiencing some very odd behaviour.
I have a prototype breatboard which only has the components as mentioned above. I'm monitoring the application via serial.print output statements. Nothing happens at all, until I move my finger over the bread board. I'm not touching anything, just moving my finger over the components, on the serial output I see that the input is going high momentarially then low again, this happens very realiabily as I move my hand back and forth.
Is this normal?
|
|
|
|
|
Logged
|
Kind Regards, Sy
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 249
Posts: 16544
Available for Design & Build services
|
 |
« Reply #3 on: February 01, 2012, 01:38:25 pm » |
Turn on the internal pullup resistor, will keep the pin being read from acting like an antenna.
|
|
|
|
|
Logged
|
|
|
|
|
United kingdom
Offline
Full Member
Karma: 0
Posts: 102
just think how much free time you would have if everything worked first time!!
|
 |
« Reply #4 on: February 01, 2012, 01:45:30 pm » |
Thank you, worked like a charm, now when switch depressed input is LOW, when not depressed HIGH. I can modify my code to suit.
Thanks again!
|
|
|
|
|
Logged
|
Kind Regards, Sy
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 249
Posts: 16544
Available for Design & Build services
|
 |
« Reply #5 on: February 01, 2012, 02:03:18 pm » |
There you go.
|
|
|
|
|
Logged
|
|
|
|
|
Austin, TX
Offline
Faraday Member
Karma: 41
Posts: 5171
CMiYC
|
 |
« Reply #6 on: February 02, 2012, 12:48:52 pm » |
Nothing happens at all, until I move my finger over the bread board. I have videos showing why this happens: http://www.cmiyc.com/tutorials/arduino-pull-ups/
|
|
|
|
|
Logged
|
|
|
|
|
|