Reputation: 3
This Question is a Repost, I figured I would just start all over again seeing as how there were several issues regarding context and formatting in it
The function of my program is to blink LEDs on and off through the use of a loop when one of three buttons is pressed.
When BTN_LEFT
is input and read as HIGH
, the program should ideally branch to the BLNKR_LEFT
loop where it should blink LED_LEFT
on and off until BTN_LEFT
is read as LOW
.
When BTN_HZRD
is read as HIGH
, the program should branch to the BLNKR_HZRD
loop and blink LED_LEFT
and LED_RIGHT
on and off until BTN_HZRD
is read as LOW
When BTN_RIGHT
is input and read as HIGH
, the program should branch to the BLNKR_RIGHT
loop and blink LED_RIGHT
on and off until BTN_RIGHT
is read as LOW
.
During these three BLNKR
loops, when their respective BTN
inputs are returning LOW
, the program should branch back to the INPUT
loop and continue reading for input from any of the three buttons.
// to compile: g++ redLed.s -lwiringPi -g -o redLed
// Program will power an LED when button is pressed, and when button is not pressed, LED will remain off
.equ INPUT, 0
.equ OUTPUT, 1
.equ LOW, 0
.equ HIGH, 1
.equ LED_LEFT, 29 // wiringPi 29 (bcm 21)
.equ LED_RIGHT, 28 // wiringPi 28 (bcm 20)
.equ BTN_LEFT, 23 // wiringPi 23 (bcm 13)
.equ BTN_HZRD, 22 // wiringPi 22 (bcm 6)
.equ BTN_RIGHT, 21 // wiringPi 21 (bcm 5)
.text
.global main
main:
// int main()
push {lr} // {
bl wiringPiSetup // wiringPiSetup(); // initialize the wiringPi library
// Initialize our WPI inputs and outputs
mov r0, #LED_LEFT // pinMode(29,OUTPUT); // set the wpi 29 pin for output
mov r1, #OUTPUT
bl pinMode
mov r0, #LED_RIGHT // pinMode(28,OUTPUT); // set the wpi 28 pin for output
mov r1, #OUTPUT
bl pinMode
mov r0, #BTN_LEFT // pinMode(23,INPUT); // set the wpi 23 pin for input
mov r1, #INPUT
bl pinMode
mov r0, #BTN_HZRD // pinMode(22,INPUT); // set the wpi 22 pin for input
mov r1, #INPUT
bl pinMode
mov r0, #BTN_RIGHT // pinMode(21,INPUT); // set the wpi 21 pin for input
mov r1, #INPUT
bl pinMode
// Searches for an input from any button, if there is no input, then the program will keep looping
INPUT:
// Set both LEDs to LOW
mov r0, #LED_LEFT
mov r1, #LOW
bl digitalWrite
mov r0, #LED_RIGHT
mov r1, #LOW
bl digitalWrite
// Read for input from BTN_LEFT, BTN_RIGHT, or BTN_HZRD
mov r0, #BTN_LEFT
bl digitalRead // digitalRead(BTN_LEFT);
mov r1, #HIGH
cmp r0, r1
bleq BLNKR_LEFT
// Read for input from BTN_HZRD
mov r0, #BTN_HZRD
bl digitalRead
mov r1, #HIGH
cmp r0, r1
bleq BLNKR_HZRD
// Read for input from BTN_RIGHT
mov r0, #BTN_RIGHT
bl digitalRead
mov r1, #HIGH
cmp r0, r1
bleq BLNKR_RIGHT
b INPUT
BLNKR_LEFT:
// If BTN_LEFT is not being pressed then the program will return to INPUT
mov r0, #BTN_LEFT
bl digitalRead
mov r1, #LOW
cmp r0, r1
bleq INPUT
mov r0, #LED_LEFT // digitalWrite(29,HIGH); // write high volt signal to pin 29
mov r1, #HIGH
bl digitalWrite
ldr r0, =#350 // delay(350); // Delay for 350 milliseconds
bl delay
mov r0, #LED_LEFT // digitalWrite(29,LOW); // write low voltage to wpi 29 to turn off the led
mov r1, #LOW
bl digitalWrite
ldr r0, =#350
bl delay
b BLNKR_LEFT
BLNKR_HZRD:
// If BTN_HZRD isnt being pressed then the program will branch back to INPUT
mov r0, #BTN_HZRD
bl digitalRead
mov r1, #LOW
cmp r0, r1
bleq INPUT
// Turn on both LED_LEFT and LED_RIGHT
mov r0, #LED_LEFT
mov r1, #HIGH
bl digitalWrite
mov r0, #LED_RIGHT
mov r1, #HIGH
bl digitalWrite
// delay for 350 milliseconds
ldr r0, =#350
bl delay
// Turn off both LED_LEFT and LED_RIGHT
mov r0, #LED_LEFT
mov r1, #LOW
bl digitalWrite
mov r0,#LED_RIGHT
mov r1, #LOW
bl digitalWrite
// Delay for 350 milliseconds
ldr r0, =#350
bl delay
b BLNKR_HZRD
BLNKR_RIGHT:
// If BTN_RIGHT isnt being pressed then the program will branch back to INPUT
mov r0, #BTN_RIGHT
bl digitalRead
cmp r0, #LOW
bleq INPUT
// Turn on LED_RIGHT
mov r0, #LED_RIGHT
mov r1, #HIGH
bl digitalWrite
// delay for 350 milliseconds
ldr r0, =#350
bl delay
// Turn off LED_RIGHT
mov r0,#LED_RIGHT
mov r1, #LOW
bl digitalWrite
// Delay for 350 milliseconds
ldr r0, =#350
bl delay
b BLNKR_RIGHT
mov r0, #0 // return 0;
pop {pc} // }
When I run the program, either the BLKNR_LEFT
or BLNKR_HZRD
loop will begin to run without any physical press of either of the three BTN
s, depending on which cmp
is executed first.
When I run the program, upon execution of digitalRead
for BTN_LEFT
or BTN_HZRD
, the value stored in r0
will be HIGH
even though I did not physically press the button, however, upon execution of digitalRead
for BTN_RIGHT
, r0
will correctly display either HIGH
or LOW
depending on whether the button is physically being pressed or not.
I have tried using different button switches, but that didn't seem to fix the issue with BTN_LEFT
and BTN_HZRD
returning HIGH
. Image of my wiring I believe my issue might be lying in my breadboard wiring,and any help regarding this issue would be very appreciated.
So, it turns out the pins that I had my BTN
values connected to BCM 5
BCM 6
were by default supposed to register as HIGH
, the only one that wasn't defaulted at HIGH
was BCM 13
which worked fine. I did not feel interested enough in fixing this or changing the reading of the pins so I simply re-pinned BTN_LEFT
and BTN_HZRD
to BCM 13
and BCM 19
. Of course, I re-pinned BTN_RIGHT
to BCM 26
. These three BCM pins are by default on my gpio readall
returning as LOW
and my program works fine now. Thank you guys for all the help because even though the problem was so simple I wouldn't have learnt how to use such a debugger without coming here.
Linked below is a screenshot of gpio readall
in which the voltage on BCM
pins 5
and 6
are displaying 1
, while BCM
pins 13
, 19
, and 26
are reading a voltage of 0
. I have tried using PUD_DOWN
internal resistors to combat any sort of floating pins there may be.
screenshot of gpio readall
Upvotes: 0
Views: 170