Code: Select all
#!/usr/bin/env python from time import sleep import os import RPi.GPIO as GPIO # Three buttons are connected to the BCM GPIO as follows button1 = 23 button2 = 24 button3 = 25 # Use the GPIO BCM numbering mode GPIO.setmode(GPIO.BCM) # Set the button connections as inputs GPIO.setup(button1, GPIO.IN) GPIO.setup(button2, GPIO.IN) GPIO.setup(button3, GPIO.IN) # loop forever reading the button inputs, when a button is pressed, print a message while True: if ( GPIO.input(button1) == False ): print "Button 1 pressed" if ( GPIO.input(button2) == False ): print "Button 2 pressed" if ( GPIO.input(button3)== False ): print "Button 3 pressed" # wait 1 second before going back to top of loop sleep(1);
Chill! The code is in the link from the first post. The code I posted for testing is the same code plus comments and the sound calls replaced with print statements.toxibunny wrote:Post your code, dude!
Basically correct, but the inputs are voltage sensitive and draw very little current. With just the resistor to 3.3V the voltage presented at the current draw of the input results in almost no voltage drop across the resistor. This presents very nearly 3.3V to the input -- a high, logic 1 or true level. When the switch is depressed, the very low resistance of the switch as compared to the resistor results in a 0V on the input -- a low, logic 0 or false level.krystal92586 wrote:I now understand why the loops are set to "False." Basically, the switch and the GPIO input are connected in parallel, so when the low-resistance switch is pressed, most of the current flows through it to ground instead of to the GPIO pin. Is that accurate? If so, I understand why it would play music when all of the wires are disconnected, because the GPIO pins would all read False since there's no current running to them.
It is unlikely you damaged the GPIO inputs by using pins 23, 24, 25 instead of GPIO 23, GPIO 24, GPIO 25. Looking at the pin designations shows these as GPIO 11, GPIO 8, and GND. By default the GPIO pins are set as inputs, so connecting them to GND through the switch is no issue. And connecting GND to GND...krystal92586 wrote:I hate to even ask this, but is it possible that we damaged the RPi when we had the wires connected wrong? We connected to pins 23, 24, and 25 instead of GPIO23, GPIO24, and GPIO25.
What a great community to help out a couple of rookies like this.