]> vault307.fbx.one Git - random.git/commitdiff
different projects to learn new things master
authorjimmy <jimipunk88@gmail.com>
Fri, 28 Jun 2024 01:30:02 +0000 (20:30 -0500)
committerjimmy <jimipunk88@gmail.com>
Fri, 28 Jun 2024 01:30:02 +0000 (20:30 -0500)
17 files changed:
RGB1602.py [new file with mode: 0644]
buttonLED-func.py [new file with mode: 0644]
dcmotorSetUp.py [new file with mode: 0644]
favicon.ico [new file with mode: 0644]
index.html [new file with mode: 0644]
ledButton.py [new file with mode: 0644]
ledScanner.py [new file with mode: 0644]
ledStranRAND.py [new file with mode: 0644]
ledTWINKLE.py [new file with mode: 0644]
letITglow.py [new file with mode: 0644]
letITglowthread.py [new file with mode: 0644]
luxTest.py [new file with mode: 0644]
photocellCounter.py [new file with mode: 0644]
playSong.py [new file with mode: 0644]
tempSense.py [new file with mode: 0644]
uk_trafficLights.py [new file with mode: 0644]
warHammer.py [new file with mode: 0644]

diff --git a/RGB1602.py b/RGB1602.py
new file mode 100644 (file)
index 0000000..407ef1d
--- /dev/null
@@ -0,0 +1,149 @@
+# -*- coding: utf-8 -*-\r
+import time\r
+from machine import Pin,I2C\r
+\r
+RGB1602_SDA = Pin(4)\r
+RGB1602_SCL = Pin(5)\r
+\r
+RGB1602_I2C = I2C(0,sda = RGB1602_SDA,scl = RGB1602_SCL ,freq = 400000)\r
+\r
+#Device I2C Arress\r
+LCD_ADDRESS   =  (0x7c>>1)\r
+RGB_ADDRESS   =  (0xc0>>1)\r
+\r
+#color define\r
+\r
+REG_RED    =     0x04\r
+REG_GREEN  =     0x03\r
+REG_BLUE   =     0x02\r
+REG_MODE1  =     0x00\r
+REG_MODE2  =     0x01\r
+REG_OUTPUT =     0x08\r
+LCD_CLEARDISPLAY = 0x01\r
+LCD_RETURNHOME = 0x02\r
+LCD_ENTRYMODESET = 0x04\r
+LCD_DISPLAYCONTROL = 0x08\r
+LCD_CURSORSHIFT = 0x10\r
+LCD_FUNCTIONSET = 0x20\r
+LCD_SETCGRAMADDR = 0x40\r
+LCD_SETDDRAMADDR = 0x80\r
+\r
+#flags for display entry mode\r
+LCD_ENTRYRIGHT = 0x00\r
+LCD_ENTRYLEFT = 0x02\r
+LCD_ENTRYSHIFTINCREMENT = 0x01\r
+LCD_ENTRYSHIFTDECREMENT = 0x00\r
+\r
+#flags for display on/off control\r
+LCD_DISPLAYON = 0x04\r
+LCD_DISPLAYOFF = 0x00\r
+LCD_CURSORON = 0x02\r
+LCD_CURSOROFF = 0x00\r
+LCD_BLINKON = 0x01\r
+LCD_BLINKOFF = 0x00\r
+\r
+#flags for display/cursor shift\r
+LCD_DISPLAYMOVE = 0x08\r
+LCD_CURSORMOVE = 0x00\r
+LCD_MOVERIGHT = 0x04\r
+LCD_MOVELEFT = 0x00\r
+\r
+#flags for function set\r
+LCD_8BITMODE = 0x10\r
+LCD_4BITMODE = 0x00\r
+LCD_2LINE = 0x08\r
+LCD_1LINE = 0x00\r
+LCD_5x8DOTS = 0x00\r
+\r
+\r
+class RGB1602:\r
+  def __init__(self, col, row):\r
+    self._row = row\r
+    self._col = col\r
+\r
+    self._showfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;\r
+    self.begin(self._row,self._col)\r
+\r
+        \r
+  def command(self,cmd):\r
+    RGB1602_I2C.writeto_mem(LCD_ADDRESS, 0x80, chr(cmd))\r
+\r
+  def write(self,data):\r
+    RGB1602_I2C.writeto_mem(LCD_ADDRESS, 0x40, chr(data))\r
+    \r
+  def setReg(self,reg,data):\r
+    RGB1602_I2C.writeto_mem(RGB_ADDRESS, reg, chr(data))\r
+\r
+\r
+  def setRGB(self,r,g,b):\r
+    self.setReg(REG_RED,r)\r
+    self.setReg(REG_GREEN,g)\r
+    self.setReg(REG_BLUE,b)\r
+\r
+  def setCursor(self,col,row):\r
+    if(row == 0):\r
+      col|=0x80\r
+    else:\r
+      col|=0xc0;\r
+    RGB1602_I2C.writeto(LCD_ADDRESS, bytearray([0x80,col]))\r
+\r
+  def clear(self):\r
+    self.command(LCD_CLEARDISPLAY)\r
+    time.sleep(0.002)\r
+  def printout(self,arg):\r
+    if(isinstance(arg,int)):\r
+      arg=str(arg)\r
+\r
+    for x in bytearray(arg,'utf-8'):\r
+      self.write(x)\r
+\r
+\r
+  def display(self):\r
+    self._showcontrol |= LCD_DISPLAYON \r
+    self.command(LCD_DISPLAYCONTROL | self._showcontrol)\r
+\r
\r
+  def begin(self,cols,lines):\r
+    if (lines > 1):\r
+        self._showfunction |= LCD_2LINE \r
+     \r
+    self._numlines = lines \r
+    self._currline = 0 \r
+\r
+    \r
+     \r
+    time.sleep(0.05)\r
+\r
+\r
+    # Send function set command sequence\r
+    self.command(LCD_FUNCTIONSET | self._showfunction)\r
+    #delayMicroseconds(4500);  # wait more than 4.1ms\r
+    time.sleep(0.005)\r
+    # second try\r
+    self.command(LCD_FUNCTIONSET | self._showfunction);\r
+    #delayMicroseconds(150);\r
+    time.sleep(0.005)\r
+    # third go\r
+    self.command(LCD_FUNCTIONSET | self._showfunction)\r
+    # finally, set # lines, font size, etc.\r
+    self.command(LCD_FUNCTIONSET | self._showfunction)\r
+    # turn the display on with no cursor or blinking default\r
+    self._showcontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF \r
+    self.display()\r
+    # clear it off\r
+    self.clear()\r
+    # Initialize to default text direction (for romance languages)\r
+    self._showmode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT \r
+    # set the entry mode\r
+    self.command(LCD_ENTRYMODESET | self._showmode);\r
+    # backlight init\r
+    self.setReg(REG_MODE1, 0)\r
+    # set LEDs controllable by both PWM and GRPPWM registers\r
+    self.setReg(REG_OUTPUT, 0xFF)\r
+    # set MODE2 values\r
+    # 0010 0000 -> 0x20  (DMBLNK to 1, ie blinky mode)\r
+    self.setReg(REG_MODE2, 0x20)\r
+    self.setColorWhite()\r
+\r
+  def setColorWhite(self):\r
+    self.setRGB(255, 255, 255)\r
diff --git a/buttonLED-func.py b/buttonLED-func.py
new file mode 100644 (file)
index 0000000..d980dce
--- /dev/null
@@ -0,0 +1,12 @@
+from machine import Pin
+import utime
+led=Pin(15,Pin.OUT)
+button=Pin(13,Pin.IN)
+led1=Pin(16,Pin.OUT)
+button1=Pin(14,Pin.IN)
+def button_press(pin):
+    led.toggle()
+def button1_press(pin):
+    led1.toggle()
+button.irq(trigger=Pin.IRQ_RISING,handler=button_press)
+button1.irq(trigger=Pin.IRQ_RISING,handler=button1_press)
\ No newline at end of file
diff --git a/dcmotorSetUp.py b/dcmotorSetUp.py
new file mode 100644 (file)
index 0000000..f7f3eeb
--- /dev/null
@@ -0,0 +1,7 @@
+from machine import Pin, PWM
+import time
+
+pwma=Pin(7,Pin.OUT)
+ain1=PWM(Pin(12))
+ain2=PWM(Pin(11))
+
diff --git a/favicon.ico b/favicon.ico
new file mode 100644 (file)
index 0000000..a5cee0b
Binary files /dev/null and b/favicon.ico differ
diff --git a/index.html b/index.html
new file mode 100644 (file)
index 0000000..164d328
--- /dev/null
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8" />
+<meta name="viewport" content="width=device-width, initial-scale=1.0" />
+<style>
+    body{background-color: pink;}
+</style>
+</head>
+<body>
+<form action="./lighton">
+<input type="submit" value="Cat on" />
+</form>
+<form action="./lightoff" />
+<input type="submit" value="Cat off" />
+</form>
+<form action="./redon">
+<input type="submit" value="Red on"/>
+</form>
+<form action="./redoff">
+<input type="submit" value="Red off"/>
+</form>
+<form action="./greenon">
+<input type="submit" value="Green on"/>
+</form>
+<form action="./greenoff">
+<input type="submit" value="Green off"/>
+</form>
+<h1>LEDs</h1>
+<p>Cat is state </p>
+<p>Red is RState </p>
+<p>Green is GSTate </p>
+<h2>Environmental Stats</h2>
+<p>Temperature is temp </p>
+<p>Relative Humidity is relHum % </p>
+</body>
+</html>
\ No newline at end of file
diff --git a/ledButton.py b/ledButton.py
new file mode 100644 (file)
index 0000000..bd01fcf
--- /dev/null
@@ -0,0 +1,10 @@
+from machine import Pin
+import time
+
+led=Pin(15,Pin.OUT)
+button=Pin(14,Pin.IN,Pin.PULL_DOWN)
+
+while True:
+    if button.value():
+        led.toggle()
+        time.sleep(.0)
diff --git a/ledScanner.py b/ledScanner.py
new file mode 100644 (file)
index 0000000..6251abd
--- /dev/null
@@ -0,0 +1,28 @@
+from machine import Pin
+import time
+
+# Set up LED pins
+seg1 = Pin(13, Pin.OUT)
+seg2 = Pin(12, Pin.OUT)
+seg3 = Pin(11, Pin.OUT)
+seg4 = Pin(10, Pin.OUT)
+seg5 = Pin(9, Pin.OUT)
+
+# Create a list of our LEDs
+segments = [seg1, seg2, seg3, seg4, seg5]
+
+while True:
+
+    # For loop to turn each LED on then off in order of the list
+    for led in segments:
+        
+        led.value(1)
+        time.sleep(0.08)
+        led.value(0)
+        
+    # For loop in reverse, running backwards through the list
+    for led in reversed (segments):
+        
+        led.value(1)
+        time.sleep(0.08)
+        led.value(0)
diff --git a/ledStranRAND.py b/ledStranRAND.py
new file mode 100644 (file)
index 0000000..7817008
--- /dev/null
@@ -0,0 +1,42 @@
+# Imports
+from machine import Pin
+from neopixel import NeoPixel
+import time, random
+
+# LED details
+GPIOnumber = 28
+LEDcount = 15
+
+# Define the strand pin number and number of LEDs from variables
+strand = NeoPixel(Pin(GPIOnumber), LEDcount)
+
+# Turn off all LEDs before program start
+strand.fill((0,0,0))
+strand.write()
+time.sleep(1)
+        
+while True:
+    mycolour = random.randint(0,256),random.randint(0,256),random.randint(0,256)
+
+    for i in range(LEDcount):
+        
+        strand[i] = (mycolour)
+        strand.write()
+        
+        # Show the light for this long
+        time.sleep(.09)
+        
+        #Clear the strand at the end of each loop
+        strand.fill((0,0,0))
+        strand.write()
+
+    for i in reversed (range(LEDcount)):
+        strand[i] =(mycolour)
+        strand.write()
+        
+        # Show the light for this long
+        time.sleep(.09)
+        
+        #Clear the strand at the end of each loop
+        strand.fill((0,0,0))
+        strand.write()
diff --git a/ledTWINKLE.py b/ledTWINKLE.py
new file mode 100644 (file)
index 0000000..367edaa
--- /dev/null
@@ -0,0 +1,48 @@
+# Imports
+from machine import Pin
+from neopixel import NeoPixel
+import time, random
+
+# LED details
+GPIOnumber = 28
+LEDcount = 15
+
+# set up buttons
+cBtn=Pin(16,Pin.IN,Pin.PULL_UP)
+sBtn=Pin(17,Pin.IN,Pin.PULL_UP)
+
+# Define the strand pin number and number of LEDs from variables
+strand = NeoPixel(Pin(GPIOnumber), LEDcount)
+
+global mycolour
+mycolour=(78,0,45)
+# Turn off all LEDs before program start
+strand.fill((mycolour))
+strand.write()
+time.sleep(1)
+
+def ledStrand():
+    i=random.randint(0,LEDcount-1)
+    strand[i]=(0,0,0)
+    strand.write()
+    time.sleep(0.09)
+    strand[i]=(mycolour)
+    strand.write()
+    time.sleep(0.09)
+    
+def nColor():
+    global mycolour
+    mycolour=(random.randint(0,255),random.randint(0,255),random.randint(0,255))
+    time.sleep(0.09)
+    
+def clearStrand():
+    strand.fill((0,0,0))
+    strand.write()
+
+while True:
+    ledStrand()
+    if sBtn.value()==0:
+        clearStrand()
+        break
+    if cBtn.value()==0:
+        nColor()
\ No newline at end of file
diff --git a/letITglow.py b/letITglow.py
new file mode 100644 (file)
index 0000000..61fc6e7
--- /dev/null
@@ -0,0 +1,61 @@
+from machine import Pin
+from neopixel import NeoPixel
+import time, random
+
+# Set up LED pins
+seg1 = Pin(0, Pin.OUT)
+seg2 = Pin(1, Pin.OUT)
+seg3 = Pin(2, Pin.OUT)
+seg4 = Pin(3, Pin.OUT)
+seg5 = Pin(4, Pin.OUT)
+seg6 = Pin(6, Pin.OUT)
+
+# Create a list of our LEDs
+segments = [seg1, seg2, seg3, seg4, seg5, seg6]
+
+# Set up buttons
+greenbtn = Pin(14, Pin.IN, Pin.PULL_DOWN)
+redbtn = Pin(15, Pin.IN, Pin.PULL_DOWN)
+
+# Define the strip pin number (2) and number of LEDs (12)
+ring = NeoPixel(Pin(16), 12)
+
+# Initialize ring
+ring.fill((0,0,0))
+ring.write()
+time.sleep(1)
+
+while True:
+
+    # For loop to turn each LED on then off in order of the list
+    for led in segments:
+        
+        led.value(1)
+        time.sleep(0.08)
+        led.value(0)
+        
+    # For loop in reverse, running backwards through the list
+    for led in reversed (segments):
+        
+        led.value(1)
+        time.sleep(0.08)
+        led.value(0)
+        
+    # Create random RGB values
+    r = random.randint(0,100)
+    g = random.randint(0,100)
+    b = random.randint(0,100)
+    
+    for i in range(12):
+        
+        # Light each LED a random colour
+        ring[i] = (r,g,b)
+        ring.write()
+        
+        # Show the LED for this long
+        time.sleep(0.05)
+        
+        #Clear the ring at the end of each loop
+        ring.fill((0,0,0))
+        ring.write()
+
diff --git a/letITglowthread.py b/letITglowthread.py
new file mode 100644 (file)
index 0000000..ada0371
--- /dev/null
@@ -0,0 +1,72 @@
+from machine import Pin
+from neopixel import NeoPixel
+import time, _thread, random
+
+# Set up LED pins
+seg1 = Pin(0, Pin.OUT)
+seg2 = Pin(1, Pin.OUT)
+seg3 = Pin(2, Pin.OUT)
+seg4 = Pin(3, Pin.OUT)
+seg5 = Pin(4, Pin.OUT)
+seg6 = Pin(6, Pin.OUT)
+
+# Create a list of our LEDs
+segments = [seg1, seg2, seg3, seg4, seg5, seg6]
+
+# Set up buttons
+greenbtn = Pin(14, Pin.IN, Pin.PULL_DOWN)
+redbtn = Pin(15, Pin.IN, Pin.PULL_DOWN)
+
+# Define the strip pin number (2) and number of LEDs (12)
+ring = NeoPixel(Pin(16), 12)
+
+# Initialize ring
+ring.fill((0,0,0))
+ring.write()
+time.sleep(1)
+
+#r = random.randint(0,100)
+#g = random.randint(0,100)
+#b = random.randint(0,100)
+
+#while True:
+def ledScan():
+    # For loop to turn each LED on then off in order of the list
+    for led in segments:
+
+        led.value(1)
+        time.sleep(0.08)
+        led.value(0)
+    # For loop in reverse, running backwards through the list
+    for led in reversed (segments):
+
+        led.value(1)
+        time.sleep(0.08)
+        led.value(0)
+
+def colorRing():
+    # Create random RGB values
+    r = random.randint(0,100)
+    g = random.randint(0,100)
+    b = random.randint(0,100)
+
+    for i in range(12):
+
+        # Light each LED a random colour
+        ring[i] = (r,g,b)
+        ring.write()
+
+        # Show the LED for this long
+        time.sleep(0.05)
+
+        #Clear the ring at the end of each loop
+        #ring.fill((0,0,0))
+        ring.write()
+while True:
+    #ledScan()
+    if greenbtn.value()==1:
+        _thread.start_new_thread(colorRing(),())
+    if redbtn.value()==1:
+        ring.fill((0,0,0))
+        ring.write()
+    ledScan()
\ No newline at end of file
diff --git a/luxTest.py b/luxTest.py
new file mode 100644 (file)
index 0000000..0669a24
--- /dev/null
@@ -0,0 +1,18 @@
+from machine import Pin, I2C
+import veml7700
+import time
+
+i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=10000) # connected on i2c0
+
+veml = veml7700.VEML7700(address=0x10, i2c=i2c, it=100, gain=1/8)
+
+def measure():
+    lux_val = veml.read_lux()
+    return(lux_val)
+
+while True:
+    lux_val=measure()
+    print(int(lux_val))
+    time.sleep(1)
+if KeyboardInterrupt:
+    pass
\ No newline at end of file
diff --git a/photocellCounter.py b/photocellCounter.py
new file mode 100644 (file)
index 0000000..cd5786e
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/env micropython
+from machine import ADC, Pin
+from time import sleep
+from machine import RTC
+
+
+
+photoPIN=26
+led=Pin(13,Pin.OUT)
+rtc=RTC()
+
+
+def readLight(photoGP):
+    photoRes=ADC(Pin(26))
+    light=photoRes.read_u16()
+    light=round(light/65535*100,2)
+    return light
+
+file=open('photoLog.txt','w')
+while True:
+    file.write("light: "+str(readLight(photoPIN))+"%"+ str(rtc.datetime())+"\n")
+    file.flush()
+    print("light: " + str(readLight(photoPIN)) +"%")
+    print(rtc.datetime())
+    sleep(900)
+    
\ No newline at end of file
diff --git a/playSong.py b/playSong.py
new file mode 100644 (file)
index 0000000..5edcbea
--- /dev/null
@@ -0,0 +1,114 @@
+from machine import Pin, PWM
+from utime import sleep
+buzzer = PWM(Pin(16))
+
+tones = {
+"B0": 31,
+"C1": 33,
+"CS1": 35,
+"D1": 37,
+"DS1": 39,
+"E1": 41,
+"F1": 44,
+"FS1": 46,
+"G1": 49,
+"GS1": 52,
+"A1": 55,
+"AS1": 58,
+"B1": 62,
+"C2": 65,
+"CS2": 69,
+"D2": 73,
+"DS2": 78,
+"E2": 82,
+"F2": 87,
+"FS2": 93,
+"G2": 98,
+"GS2": 104,
+"A2": 110,
+"AS2": 117,
+"B2": 123,
+"C3": 131,
+"CS3": 139,
+"D3": 147,
+"DS3": 156,
+"E3": 165,
+"F3": 175,
+"FS3": 185,
+"G3": 196,
+"GS3": 208,
+"A3": 220,
+"AS3": 233,
+"B3": 247,
+"C4": 262,
+"CS4": 277,
+"D4": 294,
+"DS4": 311,
+"E4": 330,
+"F4": 349,
+"FS4": 370,
+"G4": 392,
+"GS4": 415,
+"A4": 440,
+"AS4": 466,
+"B4": 494,
+"C5": 523,
+"CS5": 554,
+"D5": 587,
+"DS5": 622,
+"E5": 659,
+"F5": 698,
+"FS5": 740,
+"G5": 784,
+"GS5": 831,
+"A5": 880,
+"AS5": 932,
+"B5": 988,
+"C6": 1047,
+"CS6": 1109,
+"D6": 1175,
+"DS6": 1245,
+"E6": 1319,
+"F6": 1397,
+"FS6": 1480,
+"G6": 1568,
+"GS6": 1661,
+"A6": 1760,
+"AS6": 1865,
+"B6": 1976,
+"C7": 2093,
+"CS7": 2217,
+"D7": 2349,
+"DS7": 2489,
+"E7": 2637,
+"F7": 2794,
+"FS7": 2960,
+"G7": 3136,
+"GS7": 3322,
+"A7": 3520,
+"AS7": 3729,
+"B7": 3951,
+"C8": 4186,
+"CS8": 4435,
+"D8": 4699,
+"DS8": 4978
+}
+
+song = ["E5","G5","A5","P","E5","G5","B5","A5","P","E5","G5","A5","P","G5","E5"]
+
+def playtone(frequency):
+    buzzer.duty_u16(2000)
+    buzzer.freq(frequency)
+
+def bequiet():
+    buzzer.duty_u16(0)
+
+def playsong(mysong):
+    for i in range(len(mysong)):
+        if (mysong[i] == "P"):
+            bequiet()
+        else:
+            playtone(tones[mysong[i]])
+        sleep(0.3)
+    bequiet()
+playsong(song)
\ No newline at end of file
diff --git a/tempSense.py b/tempSense.py
new file mode 100644 (file)
index 0000000..7aa6155
--- /dev/null
@@ -0,0 +1,4 @@
+import machine, si7021, time
+
+temp_sensor=si7021.Si7021(machine.I2C(0,sda=machine.Pin(0),scl=machine.Pin(1),freq=400000))
+
diff --git a/uk_trafficLights.py b/uk_trafficLights.py
new file mode 100644 (file)
index 0000000..a065bf4
--- /dev/null
@@ -0,0 +1,20 @@
+import machine
+import utime
+
+led_red=machine.Pin(15,machine.Pin.OUT)
+led_yellow=machine.Pin(14,machine.Pin.OUT)
+led_green=machine.Pin(13,machine.Pin.OUT)
+
+while True:
+    led_red.value(1)
+    utime.sleep(5)
+    led_yellow.value(1)
+    utime.sleep(2)
+    led_red.value(0)
+    led_yellow.value(0)
+    led_green.value(1)
+    utime.sleep(5)
+    led_green.value(0)
+    led_yellow.value(1)
+    utime.sleep(5)
+    led_yellow.value(0)
\ No newline at end of file
diff --git a/warHammer.py b/warHammer.py
new file mode 100644 (file)
index 0000000..29e0da5
--- /dev/null
@@ -0,0 +1,145 @@
+from machine import Pin, PWM
+import time
+import _thread
+
+red=PWM(Pin(15))
+red.freq(5000)
+red.duty_u16(65535)
+blue=PWM(Pin(14))
+blue.freq(5000)
+blue.duty_u16(0)
+green=PWM(Pin(13))
+green.freq(5000)
+green.duty_u16(0)
+
+led1=Pin(16,Pin.OUT) #BR1
+led2=Pin(17,Pin.OUT) #BR2
+led3=Pin(18,Pin.OUT) #BR3
+led4=Pin(19,Pin.OUT) #BR4
+led5=Pin(20,Pin.OUT) #BR5
+br=[led1,led2,led3,led4,led5] #br[i].toggle()
+
+ledD=Pin(22,Pin.OUT) #blue LED
+ledD.value(0)
+ledA=Pin(21,Pin.OUT) #red LED
+ledA.value(1)
+
+global state
+
+
+button0=Pin(12,Pin.IN,Pin.PULL_DOWN) #control ledD&ledA
+global button0_pressed
+button0_pressed=False
+def button0_reader_thread():
+    global button0_pressed
+    while True:
+        if button0.value()==1:
+            button0_pressed=True
+        time.sleep(0.01)
+_thread.start_new_thread(button0_reader_thread,())
+while True:
+    if button0_pressed==True:
+        ledA.toggle()
+        ledD.toggle()
+        time.sleep(1)
+    button0_pressed=False
+
+while True:
+    if state==0:
+        stateZero()
+    elif state==1:
+        stateOne()
+    elif state==2:
+        stateTwo()
+    elif state==3:
+        stateThree()
+    elif state==4:
+        stateFour()
+    elif state==5:
+        stateFive()
+    elif state==6:
+        stateSix()
+    elif state==7:
+        stateSeven()
+        
+button1_presses=0
+last_time=0
+
+
+button1=Pin(11,Pin.IN,Pin.PULL_DOWN) #control RGB and phases
+
+def button1_pressed_handler():
+    global button1_presses, last_time
+    new_time=time.ticks_ms()
+    if (new_time-last_time)>200:
+        button1_presses+=1
+        last_time=new_time
+
+button1.irq(trigger=machine.Pin.IRQ_FALLING,handler=button1_pressed_handler)
+
+old_presses=0
+while True:
+    if button1_presses!=old_presses:
+        state=button1_presses
+        print(state)
+        old_presses=button1_presses
+
+
+def stateZero():
+    red.duty_u16(65535)
+    green.duty_u16(0)
+    blue.duty_u16(0)
+    #state=1
+    return
+
+def stateOne():
+    red.duty_u16(15000)
+    green.duty_u16(0)
+    blue.duty_u16(65535)
+    #state=2
+    i+=1
+    led[i].on()
+    return
+
+def stateTwo():
+    red.duty_u16(65535)
+    green.duty_u16(0)
+    blue.duty_u16(65535)
+    #state=3
+    return
+
+def stateThree():
+    red.duty_u16(35000)
+    green.duty_u16(65535)
+    blue.duty_u16(0)
+    #state=4
+    return
+
+def stateFour():
+    red.duty_u16(15000)
+    green.duty_u16(15000)
+    blue.duty_u16(65535)
+    #state=5
+    return
+
+def stateFive():
+    red.duty_u16(65535)
+    green.duty_u16(15000)
+    blue.duty_u16(0)
+    #state=6
+    return
+
+def stateSix():
+    red.duty_u16(0)
+    green.duty_u16(65535)
+    blue.duty_u16(65535)
+    #state=7
+    return
+
+def stateSeven():
+    red.duty_u16(0)
+    green.duty_u16(0)
+    blue.duty_u16(0)
+    state=0
+    button1_presses=0
+    return