Would this code send -5v to the switches alternating or is there some other way to do it?
Would this code send -5v to the switches alternating or is there some other way to do it?
Ahhhh, in a word no the code won't work and the schematic doesn't depict a working circuit.
If I read it correctly, the schematic has gpio.2 hooked up to a switch that will pull the pin high when the switch closes. If by -5V you mean ground then that won't work. The second switch, hooked up to ground and +5V, will either burn out the switch or shut down your power supply, whichever is weaker.
Your code doesn't take into account switch position. You'll need to use an IF/THEN or CASE SELECT or something like that. You really need to read the PBP manual, page 6, as there is working code to flash an LED. Except for the part about PORTB should be GPIO.x where x is the port where the LED is connected. There is also info in the book on how to hook up LEDs and switches. It's for a bigger PIC but you can see how is should be done.
Why don't you focus on getting an LED to light then move on to switches? Read the manual and start with a simple program then you can add to it.
Im on cell phone so I can't type details.
Use IF statement to check if input pins are 1 or 0, then turn on output as desired.
Check manual, must have example.
Bookmarks