LED와 Button

2024. 6. 18. 17:43Jetson

✅ 테스트

 

✅ custom

# custom.py -> 

from jetbot import Robot

robot = Robot()

def forward():
    robot.left_motor.value = 0.5 # 0 ~ 1
    robot.right_motor.value = 0.5
    
def backward():
    robot.left_motor.value = -0.5
    robot.right_motor.value = -0.5
    
def left():
    robot.left_motor.value = 0.5
    robot.right_motor.value =1.0
    
def right():
    robot.left_motor.value = 1.0
    robot.right_motor.value =0.5
    
def stop():
    robot.left_motor.value = 0.0
    robot.right_motor.value = 0.0
    
print("hello")

if __name__ == "__main__" :
    print("start")

 

 

✅ LED

import RPi.GPIO as gpio
import time

gpio.setmode(gpio.BCM)

gpio.setup(23, gpio.OUT) # blue led
gpio.setup(24, gpio.OUT) # green led

while True : 
    gpio.output(23, 0) # if 1 -> led off or 0 -> led on
    time.sleep(1)
    gpio.output(23, 1)
    time.sleep(1)

gpio.output(24, 0) # pull up jerhang 0 -> on / 1 -> off
# blingbling led 1

import RPi.GPIO as gpio
import time

gpio.setmode(gpio.BCM)

gpio.setup(23, gpio.OUT) # blue led

current_state = gpio.HIGH

while True : 
    
    if current_state == gpio.HIGH : # if now -> 1
        current_state = gpio.LOW # change -> 0
    else : # no
        current_state = gpio.HIGH # change -> 1
        
    gpio.output(23, current_state)
    time.sleep(1)
    gpio.output(23, current_state)
    time.sleep(1)
# blingbling led 2

import RPi.GPIO as gpio
import time

gpio.setmode(gpio.BCM)

gpio.setup(23, gpio.OUT) # blue led

current_state = gpio.HIGH

while True : 
    # current_state = 1 - current_state
    current_state = not current_state
    
    gpio.output(23, current_state)
    
    time.sleep(0.5)
# XOR yeonsan -> baetajuck nonrihap

# HIGH ^ HIGH -> LOW
# HIGH ^ LOW -> HIGH
# LOW ^ HIGH -> HIGH
# LOW ^ LOW -> LOW

# blingbling led 3

import RPi.GPIO as gpio
import time

gpio.setmode(gpio.BCM)

gpio.setup(23, gpio.OUT) # blue led

current_state = gpio.HIGH

while True : 
    # current_state = current_state ^ gpio.HIGH
    current_state ^= gpio.HIGH
    
    gpio.output(23, current_state)
    
    time.sleep(0.5)

 

✅ Button

# K1 -> 8pin, K2 -> 7pin
# push -> 0 / pull -> 1

import RPi.GPIO as gpio

gpio.setmode(gpio.BCM)

gpio.setup(23, gpio.OUT)
gpio.setup(8, gpio.IN) # button -> in / led -> out

while True:
    # if k1 button push -> blue led on!
    btn = gpio.input(8)
    print(btn)
    
#     gpio.output(23, btn)
    
    if btn == 0:
        gpio.output(23, 0)
    else:
        gpio.output(23, 1)

 

✅ jetson 종료

'Jetson' 카테고리의 다른 글

Face Tracking  (1) 2024.06.21
Cat Detection  (0) 2024.06.20
FaceDetection  (0) 2024.06.20
openCV  (0) 2024.06.19
Buzzer와 RGBstrip  (0) 2024.06.19