Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Police LED Light Bar
- ; Author: Your Name
- ; Date: 15.8.2024
- .data
- patternCount equ 30
- LED1 equ 3
- LED2 equ 4
- LED3 equ 5
- LED4 equ 6
- LED5 equ 7
- LED6 equ 8
- LED7 equ 9
- LED8 equ 10
- LED9 equ 11
- LED10 equ 12
- buttonPin equ 2
- lastButtonTime dq 0
- pattern dd 0
- .code
- setup:
- ; Set LED pins as output
- mov rcx, LED1
- call pinMode
- mov rcx, LED2
- call pinMode
- mov rcx, LED3
- call pinMode
- mov rcx, LED4
- call pinMode
- mov rcx, LED5
- call pinMode
- mov rcx, LED6
- call pinMode
- mov rcx, LED7
- call pinMode
- mov rcx, LED8
- call pinMode
- mov rcx, LED9
- call pinMode
- mov rcx, LED10
- call pinMode
- ; Set button pin as input
- mov rcx, buttonPin
- mov rdx, INPUT
- call pinMode
- ret
- loop:
- ; Check if button is pressed and debounce
- mov rcx, buttonPin
- call digitalRead
- test rax, rax
- jz no_button_press
- call millis
- mov rbx, [lastButtonTime]
- sub rax, rbx
- cmp rax, 100
- jle no_button_press
- ; Update last button press time
- call millis
- mov [lastButtonTime], rax
- ; Increment pattern
- mov eax, [pattern]
- inc eax
- xor edx, edx
- mov ecx, patternCount
- div ecx
- mov [pattern], edx
- no_button_press:
- ; Switch based on pattern
- mov eax, [pattern]
- cmp eax, 1
- je pattern1
- cmp eax, 2
- je pattern2
- cmp eax, 3
- je pattern3
- jmp loop
- pattern1:
- ; LED1-5 on
- mov rcx, LED1
- mov rdx, HIGH
- call digitalWrite
- mov rcx, LED2
- call digitalWrite
- mov rcx, LED3
- call digitalWrite
- mov rcx, LED4
- call digitalWrite
- mov rcx, LED5
- call digitalWrite
- mov rcx, 50
- call delay
- ; LED1-5 off
- mov rcx, LED1
- mov rdx, LOW
- call digitalWrite
- mov rcx, LED2
- call digitalWrite
- mov rcx, LED3
- call digitalWrite
- mov rcx, LED4
- call digitalWrite
- mov rcx, LED5
- call digitalWrite
- mov rcx, 50
- call delay
- ; Repeat two more times...
- ; LED6-10 on
- mov rcx, LED6
- mov rdx, HIGH
- call digitalWrite
- mov rcx, LED7
- call digitalWrite
- mov rcx, LED8
- call digitalWrite
- mov rcx, LED9
- call digitalWrite
- mov rcx, LED10
- call digitalWrite
- mov rcx, 50
- call delay
- ; LED6-10 off
- mov rcx, LED6
- mov rdx, LOW
- call digitalWrite
- mov rcx, LED7
- call digitalWrite
- mov rcx, LED8
- call digitalWrite
- mov rcx, LED9
- call digitalWrite
- mov rcx, LED10
- call digitalWrite
- mov rcx, 50
- call delay
- ; Repeat two more times...
- jmp loop
- pattern2:
- ; Similar to pattern1, but with different timing
- pattern3:
- mov rcx, LED5
- mov rdx, HIGH
- call digitalWrite
- ; Continue with the rest of pattern3...
- jmp loop
- ; External function declarations (Arduino-like functions)
- extern pinMode
- extern digitalWrite
- extern digitalRead
- extern millis
- extern delay
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement