Rgb led with joystick


RGB led with Joy Stick

Code

main.py

from machine import Pin,ADC
import time

r = Pin(5,Pin.OUT)
b = Pin(7,Pin.OUT)
g = Pin(6,Pin.OUT)
vertical = ADC(Pin(26))
horizontal = ADC(Pin(27))

while True:
    time.sleep(0.02)
    if vertical.read_u16() > 50000:
        r.value(1)
        g.value(0)
        b.value(0)
    elif vertical.read_u16() < 10000:
        r.value(0)
        g.value(1)
        b.value(0)
    elif horizontal.read_u16() >50000:
        r.value(1)
        g.value(1)
        b.value(0)
    elif horizontal.read_u16() <10000:
        r.value(0)
        g.value(0)
        b.value(1)
    else: 
        r.value(0)
        b.value(0)
        g.value(0)

diagram.json

{
  "version": 1,
  "editor": "wokwi",
  "parts": [
    {
      "type": "wokwi-pi-pico",
      "id": "pico",
      "top": -9.33,
      "left": -59.33,
      "attrs": { "env": "micropython-20220618-v1.19.1" }
    },
    {
      "type": "wokwi-rgb-led",
      "id": "rgb1",
      "top": -81.28,
      "left": 29.42,
      "attrs": { "common": "cathode" }
    },
    {
      "type": "wokwi-analog-joystick",
      "id": "joystick1",
      "top": -92.47,
      "left": 169.13,
      "attrs": {}
    }
  ],
  "connections": [
    [ "joystick1:HORZ", "pico:GP27", "white", [ "v0" ] ],
    [ "joystick1:GND", "pico:GND.5", "black", [ "v0" ] ],
    [ "joystick1:VERT", "pico:GP26", "green", [ "v0" ] ],
    [ "joystick1:VCC", "pico:3V3", "red", [ "v0" ] ],
    [ "rgb1:COM", "pico:GND.8", "gray", [ "v0" ] ],
    [ "rgb1:R", "pico:GP5", "red", [ "v3.28", "h-147.71", "v75.82" ] ],
    [ "rgb1:G", "pico:GP6", "green", [ "v19.15", "h-154.44", "v95.22" ] ],
    [ "rgb1:B", "pico:GP7", "blue", [ "v3.87", "h15.53", "v-52.9", "h-160.46", "v175.74" ] ]
  ],
  "dependencies": {}
}

Notes mentioning this note


ນີ້ຄືກຣາຟທີ່ລິ້ງໄປຫາທຸກໜ້າໃນ garden ນີ້ 🕸️.