TonyGo

2XLW BIG-ONE v2 - I2C project

Jun 2nd, 2026
98
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 36.18 KB | Software | 0 0
  1. # 2XLW BIG-ONE v2 - Loads of INPUTS/OUTPUTS
  2. # Tony Goodhew 31th May 2026
  3. import time
  4. from machine import Pin,I2C
  5. from pimoroni_i2c import PimoroniI2C
  6. from breakout_bme280 import BreakoutBME280
  7. from breakout_ltr559 import BreakoutLTR559
  8. import ahtx0
  9. from lsm6ds3 import LSM6DS3, NORMAL_MODE_104HZ
  10. from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY_2, PEN_RGB332
  11. from pimoroni import RGBLED
  12. from pico_i2c_lcd import I2cLcd
  13. from breakout_trackball import BreakoutTrackball
  14. from neopixel import NeoPixel
  15. from ssd1306 import SSD1306_I2C
  16. from breakout_encoder import BreakoutEncoder
  17. from pimoroni import RGBLED, Button
  18. from DF2301Q_I2C import DFRobot_DF2301Q_I2C
  19. from qwstpad import QwSTPad
  20. from breakout_ioexpander import BreakoutIOExpander
  21. from aye_arr.nec import NECRemoteReceiver
  22. from aye_arr.nec.remotes import PimoroniRemote
  23. from random import randint
  24. import network
  25. import rp2
  26. import requests
  27. from secrets import WIFI_SSID, WIFI_PASSWORD
  28.  
  29. rp2.country("GB")
  30. # SPI Display 2.0" set up 320x240 Pixels
  31. display = PicoGraphics(display=DISPLAY_PICO_DISPLAY_2, pen_type=PEN_RGB332, rotate=0)
  32. display.set_backlight(0.8)
  33. display.set_font("bitmap8")
  34.  
  35. led = RGBLED(6, 7, 8)
  36. led.set_rgb(0,0,0)   # Turn off the RGB LED
  37.  
  38. width, height = display.get_bounds()
  39. # Display colours
  40. blk = display.create_pen(0, 0, 0)        #0
  41. whi = display.create_pen(255,255,255)    #255
  42. yel = display.create_pen(200,200,0)      #216
  43. grn = display.create_pen(0,255,0)        #28
  44. blu = display.create_pen(0,0,255)        #3
  45. red = display.create_pen(255,0,0)        #224
  46. mag = display.create_pen(255,0,255)
  47. cyn = display.create_pen(0,255,255)
  48.  
  49. # SETUP Buttons = NOT used at the moment
  50. global KEY_A
  51. KEY_A = Pin(12,Pin.IN,Pin.PULL_UP)
  52. #KEY_B = Pin(13,Pin.IN,Pin.PULL_UP)
  53. #KEY_X = Pin(14,Pin.IN,Pin.PULL_UP)
  54. #KEY_Y = Pin(15,Pin.IN,Pin.PULL_UP)
  55. display.set_pen(blk)
  56. display.clear()
  57. display.set_pen(yel)
  58. display.text("Display 2.0 set up",5,5,310,scale = 3)
  59. display.update()
  60.  
  61. # ====== Set up NeoPixelâ„¢ LEDs on GPIO 0 SKULL ============
  62. NUM_LEDS = 15 # No of Neopixels
  63.  
  64. np = NeoPixel(Pin(0), NUM_LEDS) # Neopixels in SKULL
  65.  
  66. # Neopixel Colours
  67. RED = (255,0,0)
  68. GREEN = (0,255,0)
  69. BLUE = (0,0,255)
  70. YELLOW = (255,255,0)
  71. CYAN = (0,255,255)
  72. MAGENTA = (255,0,255)
  73. WHITE = (255,255,255)
  74. BLACK = (0,0,0)
  75. WARM = (255,192,96)
  76. COOL = (96,192,255)
  77.  
  78. codes =[(255,0,0),(0,255,0),(0,0,255),(255,255,0),(0,255,255),(255,0,255),(255,255,255),(0,0,0),(255,192,96),(96,192,255)]
  79. colours = [RED,GREEN,BLUE,YELLOW,CYAN,MAGENTA,WHITE,BLACK,WARM,COOL] # Neopixels 3 bytes
  80. col_names = ["RED","GREEN","BLUE","YELLOW","CYAN","MAGENTA","WHITE","BLACK","WARM","COOL"] # names
  81. col_p8 = [red,grn,blu,yel,cyn,mag,whi,blk]    # Display 2.0 P8 - 1 byte
  82.  
  83. def neofill(cc):    # Skull colour fill
  84.     for i in range(NUM_LEDS):
  85.         np[i] = (cc)
  86.         np.write()
  87. neofill(GREEN)
  88. np.write()
  89.  
  90. # =========== END OF SKULL LED STRIP SET UP ================
  91.  
  92. # =========== Set up 16 RGBW Neopixels on RING ==========
  93. # Number of LEDs in your ring
  94. RING_NO = 16
  95. # Global brightness limiter (0.0–1.0)
  96. BRIGHTNESS = 0.3   # 30% brightness
  97.  
  98. # Data pin (change if needed)
  99. PIN_NUM = 38
  100.  
  101. # Create RGBW NeoPixel object
  102. ring = NeoPixel(Pin(PIN_NUM), RING_NO, bpp=4)  # bpp=4 = RGBW
  103.  
  104. ring_cols = [(255, 0, 0, 0),(207, 0, 48, 0),(159, 0, 96, 0),(111, 0, 144, 0),(63, 0, 192, 0),
  105.              (15, 0, 240, 0),(0, 33, 222, 0),(0, 81, 174, 0),(0, 129, 126, 0),
  106.             (0, 177, 78, 0),(0, 225, 30, 0),(15, 240, 0, 0),(63, 192, 0, 0),
  107.              (111, 144, 0, 0),(159, 96, 0, 0),(207, 48, 0, 0),
  108.              ]
  109.  
  110. def ring_clear():
  111.     for i in range(RING_NO):
  112.         ring[i] = (0, 0, 0, 0)
  113.     ring.write()
  114.  
  115. def apply_brightness(color):
  116.     """Scale (R,G,B,W) by global brightness."""
  117.     r, g, b, w = color
  118.     return (
  119.         int(r * BRIGHTNESS),
  120.         int(g * BRIGHTNESS),
  121.         int(b * BRIGHTNESS),
  122.         int(w * BRIGHTNESS),
  123.     )
  124.  
  125. def ring_fill(rc): # Fills ring from ring_cols list
  126. #    temp = ring_cols[rc]
  127.  
  128.     for i in range(16):
  129.         ring[i] = apply_brightness(ring_cols[rc])
  130.     ring.write()
  131.  
  132. def ring_roll_cw():
  133.     display.set_pen(blk)
  134.     display.clear()
  135.     display.set_pen(whi)
  136.     display.text("Ring Roll CW",20,100,320,scale=4)
  137.     display.update()
  138.     for iz in range(15):
  139.         pp = 0
  140.         ii = 0
  141.         tstep =iz/100.0
  142.         if tstep >= 0.07: tstep = 0.065
  143. #        print(tstep)
  144.         for qq in range(15,-1,-1):
  145.             ring_clear()
  146.             ring[qq] = apply_brightness(ring_cols[ii])
  147.             ring[(qq+1)%RING_NO] = apply_brightness(ring_cols[(ii-1)%RING_NO])
  148.             ring[(qq+2)%RING_NO] = apply_brightness(ring_cols[(ii-2)%RING_NO])
  149.             ring[(qq+3)%RING_NO] = apply_brightness(ring_cols[(ii-3)%RING_NO])        
  150.             ring.write()
  151.             time.sleep(0.07-tstep)
  152.     ring_clear()
  153.     display.set_pen(blk)
  154.     display.clear()
  155.     display.update()
  156.    
  157. def ring_roll_ccw():    
  158.     display.set_pen(blk)
  159.     display.clear()
  160.     display.set_pen(whi)
  161.     display.text("Ring Roll CCW",20,100,320,scale=4)
  162.     display.update()
  163.     for iz in range(15):
  164.         pp = 0
  165.         ii = 0
  166.         tstep =iz/100.0
  167.         if tstep >= 0.07: tstep = 0.065
  168.         for qq in range(15):
  169.             ring_clear()
  170.             ring[qq] = apply_brightness(ring_cols[ii])
  171.             ring[(qq-1)%RING_NO] = apply_brightness(ring_cols[(ii-1)%RING_NO])
  172.             ring[(qq-2)%RING_NO] = apply_brightness(ring_cols[(ii-2)%RING_NO])
  173.             ring[(qq-3)%RING_NO] = apply_brightness(ring_cols[(ii-3)%RING_NO])        
  174.             ring.write()
  175.             time.sleep(0.07-tstep)
  176.     ring_clear()
  177.     display.set_pen(blk)
  178.     display.clear()
  179.     display.update()
  180.  
  181. #Flash a ring pixel to indicate connected
  182. ring_fill(7)
  183. ring.write()
  184. time.sleep(0.4)
  185. ring_clear()
  186. # === End of Neopixel RING set up ===
  187.  
  188. # ====== IR ZAPPER RECEIVER set up ======
  189.  
  190. # Constants IR receiver
  191. IR_RX_PIN = 1          # The pin to listen for IR pulses on
  192.  
  193. # Color constants
  194. zRED = 255, 0, 0
  195. zGREEN = 0, 255, 0
  196. zBLUE = 0, 0, 255
  197. zCYAN = 0, 255, 255
  198. zMAGENTA = 255, 0, 255
  199. zYELLOW = 255, 255, 0
  200. zWARM = 255, 192, 96
  201. zWHITE = 255, 255, 255
  202. zCOOL = 96, 192, 255
  203. zBLACK = 0, 0, 0
  204.  
  205. # Function called when a colour button is pressed
  206. def set_strip(colour):
  207.     xx = codes.index(colour)
  208.     print(colour,col_names[xx])
  209.     for led in range(NUM_LEDS):
  210.         np[led] =(colour)
  211.     np.write()
  212. #    print(f"Colour = #{colour[0]:02x}{colour[1]:02x}{colour[2]:02x}")
  213.     r,g,b = colour
  214.     temp_col = display.create_pen(r,g,b)
  215.     display.set_pen(temp_col)
  216.     display.clear()
  217.     display.set_pen(blk)
  218.     if xx == 7:
  219.         display.set_pen(whi)        
  220.     display.text(col_names[xx],20,100,300,4)
  221.     display.update()
  222.     r = int(r * BRIGHTNESS)
  223.     g = int(g * BRIGHTNESS)
  224.     b = int(b * BRIGHTNESS)
  225.     for pp in range(RING_NO):
  226.         ring[pp] = (r,g,b,0)
  227.     ring.write()
  228.    
  229. def halt():
  230.     global running
  231.     running = False
  232.  
  233. # Create the remote and setup up what each of the buttons will do
  234. remote = PimoroniRemote()
  235. remote.bind("1_RED", (set_strip, zRED), on_repeat=None)
  236. remote.bind("2_GREEN", (set_strip, zGREEN), on_repeat=None)
  237. remote.bind("3_BLUE", (set_strip, zBLUE), on_repeat=None)
  238. remote.bind("4_CYAN", (set_strip, zCYAN), on_repeat=None)
  239. remote.bind("5_MAGENTA", (set_strip, zMAGENTA), on_repeat=None)
  240. remote.bind("6_YELLOW", (set_strip, zYELLOW), on_repeat=None)
  241. remote.bind("7_WARM", (set_strip, zWARM), on_repeat=None)
  242. remote.bind("8_WHITE", (set_strip, zWHITE), on_repeat=None)
  243. remote.bind("9_COOL", (set_strip, zCOOL), on_repeat=None)
  244. remote.bind("0_RAINBOW", (set_strip, zBLACK), on_repeat=None)
  245. remote.bind("ANTICLOCK", (ring_roll_ccw), on_repeat=None)
  246. remote.bind("CLOCKWISE", (ring_roll_cw), on_repeat=None)
  247. remote.bind("OK_STOP", (halt))
  248.  
  249. # Set up a receiver on the RX pin, using PIO 1 and SM 0, and bind the remote to it.
  250. receiver = NECRemoteReceiver(IR_RX_PIN, 1, 0)
  251. receiver.bind(remote)
  252.  
  253. # ============= End of Zapper set up ====================================
  254.  
  255. # ============ Set up LCD2004 on I2C bus 1 - GPIO 2 & 3 =======
  256. I2C_ADDR     = 0x27
  257. I2C_NUM_ROWS = 4
  258. I2C_NUM_COLS = 20
  259. i2c1 = I2C(1, sda=machine.Pin(2), scl=machine.Pin(3), freq=400000)
  260. lcd = I2cLcd(i2c1, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
  261. lcd.putstr("Hello, LCD set up")
  262.  
  263. # Set up I2C Bus 0 - GPIO 4 & 5
  264. PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5, "baudrate": 100000}
  265. PINS_PICO_EXPLORER = {"sda": 20, "scl": 21, "baudrate": 100000}
  266. PINS_PICO = {"sda": 4, "scl": 5, "baudrate": 100000}
  267. i2c = PimoroniI2C(**PINS_PICO)
  268.  
  269. # Connect I2C components to I2C Bus 0
  270. # Starting with Voice Recognition board
  271. '''
  272. https://nerdcave.xyz/docs/tutorials/gravity-offline-language-learning-voice-recognition-sensor/
  273. # Basic code to test the board
  274. # Say "Hello, Robot"
  275. #     "Learn cmd word"
  276. #     "Exit learning"
  277. #     "Learn wake word"
  278. #     "I want to delete"
  279. #     "Delete cmd word"
  280. #     "Delete all"
  281.  
  282. Initial learned codes 23 March 2026
  283. COMMAND ID: 5  stop
  284. COMMAND ID: 6  red
  285. COMMAND ID: 7  green
  286. COMMAND ID: 8  blue
  287. COMMAND ID: 9  yellow
  288. COMMAND ID: 10 cyan
  289. COMMAND ID: 11 magenta
  290. COMMAND ID: 12 white
  291. COMMAND ID: 13 black
  292. '''
  293.  
  294. def setup(sensor) -> None:
  295.  
  296.     """
  297.    Set up the DFRobot DF2301Q sensor
  298.    :param sensor: instance of DFRobot_DF2301Q_I2C
  299.    :return: None
  300.    """
  301.     sensor.set_volume(7)      # 10
  302.     sensor.set_mute_mode(0)   # 0
  303.     sensor.set_wake_time(20)  # 20
  304.  
  305. def get_cmd_id(sensor) -> int:
  306.     """
  307.    Get the command id from the DF2301Q sensor
  308.    :param sensor: instance of DFRobot_DF2301Q_I2C
  309.    :return: int
  310.    """
  311.     command_id = sensor.get_cmdid()
  312.  
  313.     if command_id != 0:
  314.         return int(command_id)
  315.  
  316. # === End of VOICE SUPPORT ========================
  317.  
  318. # === Set up the other I2C devices =============
  319. try:
  320.     # Check sensors connected
  321.     bme = BreakoutBME280(i2c, address=0x76)
  322.     ltr = BreakoutLTR559(i2c)
  323.     aht20 = ahtx0.AHT20(i2c)
  324.     mov_sensor = LSM6DS3(i2c, mode=NORMAL_MODE_104HZ)
  325.     #Set up TrackBall
  326.     trackball = BreakoutTrackball(i2c)
  327.     trackball.set_rgbw(0, 0, 0, 64)
  328.     sensitivity = 2
  329.     #Set up OLED display
  330.     WIDTH  = 128          # oled display width
  331.     HEIGHT = 32
  332.     # Advent SSD1306 and usual majority of displays
  333.     oled = SSD1306_I2C(128,64,i2c)
  334.     oled.fill(0)
  335.     oled.show()
  336.     # Rotary Encoder
  337.     enc = BreakoutEncoder(i2c)
  338.     STEPS_PER_REV = 24
  339.     enc.set_led(0,0,0)
  340.     enc.set_brightness(1.0)
  341.     # enc.set_direction(BreakoutEncoder.DIRECTION_CCW)     # Uncomment this to flip the direction
  342.     # Qw/ST Pad
  343.     qwstpad = QwSTPad(i2c, 0x21)
  344.    
  345.     # Voice recognition
  346.     SLEEP_SECONDS = 2
  347.     voice_sensor = DFRobot_DF2301Q_I2C(sda=4, scl=5)
  348.     setup(sensor=voice_sensor)
  349. except RuntimeError:
  350.     print("I2C connection problem!")
  351.  
  352. # Check all I2C devices have been set up
  353. print('Scanning I2C bus.')
  354. devices = i2c.scan() # this returns a list of devices
  355.  
  356. device_count = len(devices)
  357.  
  358. if device_count == 0:
  359.     print('No i2c device found.')
  360. else:
  361.     print(device_count, 'devices found.') # Should be 10
  362.  
  363. for device in devices:
  364.     print('Decimal address:', device, ", Hex address: ", hex(device))
  365.  
  366. # Report Bus 0 I2C items
  367. lcd.move_to(0,2)
  368. lcd.putstr("Items on I2C bus 0")
  369. lcd.move_to(8,3)
  370. lcd.putstr(str(device_count))
  371.  
  372. # Wake up lux sensor - LTR559
  373. prox, a, b, c, d, e, lux = ltr.get_reading()
  374. time.sleep(0.5)
  375.  
  376. # Procedure to draw enlarged text on SSD1306
  377. # using the built-in font
  378. def xtext(string,xx,yy,size):
  379.     ln = len(string)
  380.     oled.text(string,0,56,1) # Normal size string
  381.     for yq in range(8):
  382.         for xq in range(ln*8):
  383.             px = oled.pixel(0+xq,56+yq) # Get pixel value
  384.             if px == 1:
  385.                 oled.rect(xx+xq*size,yy+yq*size,size,size,1,1)
  386.     oled.rect(0,56,ln*8,8,0,1) # Clear temp text area
  387.  
  388. # Set up IO Expander add-on compenents and 3x'normal 10K pots' on ADC pins
  389. ioe = BreakoutIOExpander(i2c, address=0x18)
  390. ioe_button_pin = 2
  391. ioe.set_mode(ioe_button_pin, BreakoutIOExpander.PIN_IN_PU)
  392. state = ioe.input(ioe_button_pin)
  393.  
  394. # Potentiometer - ADC input on IO Expander
  395. ioe_adc_pin = 10
  396. ioe.set_mode(ioe_adc_pin, BreakoutIOExpander.PIN_ADC)
  397.  
  398. # Set up the 10 K potentiometers in a list on Pici ADC pins
  399. pots = [] # Empty list of potentiometers
  400. for i in range(3):
  401.     pot = machine.ADC(i)# 0, 1 or 2
  402.     pots.append(pot)
  403.  
  404. # Function to get a number from the position of the potentiometer knob
  405. # Overcomes 'iffy zero' to true range 0 - 255 -- soft ends!
  406. def get_pot_no(adc, maxx):
  407.     max2 = maxx + 6
  408.     reading = pots[adc].read_u16()
  409.     # Adjust low end
  410.     reading = reading - 400
  411.     if reading < 0:
  412.         reading = 0
  413.     result = int((max2 * reading)/(65535-400)) # rescale
  414.     # Adjust top end
  415.     if result > maxx:
  416.         result = maxx
  417.     return result # Send answer back to main program
  418.  
  419. # set up RGB PWM LEDs on IO Expander
  420. # Setup colour control pins
  421. adj = 65500/256
  422. rd = 1
  423. green = 3
  424. blue = 5
  425.  
  426. # Setup PWM timer
  427. # Settings to produce a 50Hz output from the 24MHz clock.
  428. # 24,000,000 Hz / 8 = 3,000,000 Hz
  429. # 3,000,000 Hz / 60,000 Period = 50 Hz
  430. divider = 8
  431. period = 60000
  432.  
  433. ioe.set_pwm_period(period) # 50 Hz
  434. ioe.set_pwm_control(divider)
  435.  
  436. # Setup PWM pins for RGBLED
  437. ioe.set_mode(rd, BreakoutIOExpander.PIN_PWM)
  438. ioe.set_mode(green, BreakoutIOExpander.PIN_PWM)
  439. ioe.set_mode(blue, BreakoutIOExpander.PIN_PWM)
  440.  
  441. # Flash red LED - setup progress indicator
  442. ioe_LED_pin = 6
  443. ioe.set_mode(ioe_LED_pin, BreakoutIOExpander.PIN_OUT)
  444. for i in range(3):
  445.     ioe.output(ioe_LED_pin, 1)
  446.     time.sleep(0.2)
  447.     ioe.output(ioe_LED_pin, 0)
  448.     time.sleep(0.2)
  449.  
  450. # == End of IO Exp set up =========
  451.  
  452. # ===== Set up NeoPixelâ„¢ LEDs on GPIO 0  - in the SKULL bottle ======
  453. NUM_LEDS = 15 # No of Neopixels
  454. np = NeoPixel(Pin(0), NUM_LEDS)
  455.  
  456. #=============================
  457.  
  458. def tidy_up(): # Turn OFF the lights
  459.     for i in range(NUM_LEDS): # SKULL
  460.         np[i] = (0,0,0)
  461.     np.write()
  462.     oled.fill(0)             # OLED
  463.     oled.show()
  464.     lcd.clear()              # LCD
  465.     enc.set_led(0,0,0)       # Rot Enc
  466.     trackball.set_rgbw(0,0,0, 0)  # TB
  467.     display.set_pen(blk)     # Display 2
  468.     display.clear()
  469.     display.update()
  470.     ring_clear()             # RING
  471.     ioe.output(rd, 0)        # RGBLED on IO Exp
  472.     ioe.output(green, 0)
  473.     ioe.output(blue, 0)
  474.  
  475. # ==========  MENU PROCs ===================
  476. # ========== Environmental sensing  ======
  477.  
  478. def sensing():
  479.     display.set_pen(blk)
  480.     display.clear()
  481.     display.set_pen(whi)
  482.     display.text("Sensing",20,100,320,scale=4)
  483.     display.update()
  484.     running = True
  485.     lcd.clear()
  486.     lcd.move_to(3,0)
  487.     lcd.putstr("Environmental")
  488.     lcd.move_to(6,1)
  489.     lcd.putstr("Sensing")
  490.     lcd.move_to(1,2)
  491.     lcd.putstr("On Coloured Screen")
  492.     lcd.move_to(3,3)
  493.     lcd.putstr("Menu: Button")
  494.     display.set_pen(blk)
  495.     display.clear()
  496.     display.set_pen(yel)
  497.     display.update()
  498.     running = True
  499.     while running:
  500.         # Read the AHT20 sensors
  501.         display.set_pen(blk)
  502.         neofill(CYAN)
  503.         oled.fill(0)
  504.         xtext("AHT20",10,10,2)
  505.         oled.show()
  506.         display.clear()
  507.         display.set_pen(yel)
  508.         display.text("AHT20", 20,20, 220, scale=4)
  509.         print("\nAHT20")
  510.         display.set_pen(whi)
  511.         print("Temperature: %0.2f C" % aht20.temperature)
  512.         display.text("Temperature: %0.2f C" % aht20.temperature,20,70,220,scale = 2)
  513.         print("Humidity: %0.2f %%" % aht20.relative_humidity)
  514.         display.text("Humidity: %0.2f %%" % aht20.relative_humidity,20,120,220, scale =2)
  515.         display.update()
  516.         time.sleep(3)
  517.         if ioe.input(ioe_button_pin) == 0:
  518.             running = False
  519.             break
  520.        
  521.         # Read the bme280 sensors
  522.         neofill(RED)
  523.         temperature, pressure, humidity = bme.read()
  524.         temp = round(temperature,2)
  525.  
  526.         # Convert pressure to hPa
  527.         pressurehpa = int(pressure / 100)
  528.         display.set_pen(blk)
  529.         display.clear()
  530.         if ioe.input(ioe_button_pin) == 0:
  531.             running = False
  532.             break
  533.        
  534.         print("\nBME280")
  535.         oled.fill(0)
  536.         xtext("BME280",10,10,2)
  537.         oled.show()
  538.         display.set_pen(yel)
  539.         display.text("BME280", 20,20, 220, scale=4)
  540.         display.set_pen(whi)
  541.         display.text("Temperature: "+str(temp)+" C",20,70,220,scale = 2)
  542.         display.text("Humidity: "+str(int(humidity)) +" %",20,120,200,scale = 2)
  543.         display.text("Pressure: "+str(pressurehpa)+" hPa",20,170,scale = 2)
  544.         display.update()    
  545.         print("Temperature: "+str(temp)+" C")
  546.         print("Humidity: "+str(int(humidity)) +" %")
  547.         print("Pressure: "+str(pressurehpa)+" hPa")
  548.         time.sleep(3)
  549.         if ioe.input(ioe_button_pin) == 0:
  550.             running = False
  551.             break
  552.        
  553.         # Read LTR559
  554.         neofill(BLUE)
  555.         prox, a, b, c, d, e, lux = ltr.get_reading()
  556.         lux = int(lux)
  557.         oled.fill(0)
  558.         xtext("LTR559",10,10,2)
  559.         oled.show()
  560.         display.set_pen(blk)
  561.         display.clear()
  562.         display.set_pen(yel)
  563.         display.text("LTR559", 20,20, 220, scale=4)
  564.         display.set_pen(whi)
  565.         display.text("Lux: "+str(lux),20,70,220,scale = 2)
  566.         print("\nLTR559\n"+str(lux),"LUX")
  567.         display.update()
  568.         time.sleep(3)
  569.         if ioe.input(ioe_button_pin) == 0:
  570.             running = False
  571.             break
  572.        
  573.         # Read LSM6DS3
  574.         neofill(MAGENTA)
  575.         display.set_pen(blk)
  576.         display.clear()
  577.         display.set_pen(yel)
  578.         display.text("LSM6DS3", 20,20, 220, scale=4)
  579.         oled.fill(0)
  580.         xtext("LSM6DS3",10,10,2)
  581.         oled.show()
  582.         ax, ay, az, gx, gy, gz = mov_sensor.get_readings()
  583.         display.set_pen(whi)
  584.         display.text("\nAccelerometer\nX:{}, Y:{}, Z:{}\n\nGyro\nX:{}, Y:{}, Z{}\n\n ".format(ax, ay, az, gx, gy, gz),20,70,220,scale = 2)
  585.         display.update()
  586.         time.sleep(3)
  587.         if ioe.input(ioe_button_pin) == 0:
  588.             running = False
  589.             break
  590.     tidy_up()
  591.  
  592. # ========= Rotary Encoder Section ===========
  593. def hsv_to_rgb(h, s, v):
  594.     # From CPython Lib/colorsys.py
  595.     if s == 0.0:
  596.         return v, v, v
  597.     i = int(h * 6.0)
  598.     f = (h * 6.0) - i
  599.     p = v * (1.0 - s)
  600.     q = v * (1.0 - s * f)
  601.     t = v * (1.0 - s * (1.0 - f))
  602.     i = i % 6
  603.     if i == 0:
  604.         return v, t, p
  605.     if i == 1:
  606.         return q, v, p
  607.     if i == 2:
  608.         return p, v, t
  609.     if i == 3:
  610.         return p, q, v
  611.     if i == 4:
  612.         return t, p, v
  613.     # if i == 5:
  614.     return v, p, q
  615.  
  616. # === Lights routine ===
  617. def lights(r,g,b,position):
  618.     # Colour the SKULL
  619.     if (position < 0) or (position > 15):
  620.         for i in range(NUM_LEDS):
  621.             np[i] = (r,g,b)
  622.     else:
  623.         for i in range(NUM_LEDS):
  624.             np[i] = (0,0,0)
  625.         np[position] = (r,g,b)
  626.     np.write()
  627.     trackball.set_rgbw(r,g,b, 0)
  628.     display.set_pen(blk)
  629.     display.clear()        
  630.     led.set_rgb(0,0,0)   # RGB LED
  631.     xb = 100
  632.     display.set_pen(red)
  633.     display.text("R",15,53,310,scale = 3)
  634.     display.rectangle(xb, 50, int(r*0.8), 30)
  635.     display.set_pen(whi)
  636.     display.text(str(r),60,58,310,scale = 2)
  637.     display.set_pen(grn)
  638.     display.text("G",15,103,310,scale = 3)
  639.     display.rectangle(xb, 100, int(g*0.8), 30)
  640.     display.set_pen(whi)
  641.     display.text(str(g),60,108,310,scale = 2)
  642.     display.set_pen(blu)
  643.     display.text("B",15,153,310,scale = 3)
  644.     display.rectangle(xb, 150, int(b*0.8), 30)
  645.     display.set_pen(whi)
  646.     display.text(str(b),60,158,310,scale = 2)
  647.     c2 = display.create_pen(r,g,b)
  648.     display.set_pen(whi)
  649.     display.text("Mixed",15,203,310,scale = 3)
  650.     display.set_pen(c2)
  651.     display.rectangle(xb, 200, int(255*0.8), 30)
  652. #    display.update()
  653.     enc.set_led(r,g,b)
  654.     r2 = int(r * adj /2)
  655.     g2 = int(g * adj /2)
  656.     b2 = int(b * adj /2)
  657.     # RGB LED
  658.     ioe.output(rd, r2)
  659.     ioe.output(green, g2)
  660.     ioe.output(blue, b2)
  661.     if (position >= 0) and (position <= 14):
  662.         temp_col = display.create_pen(r,g,b)
  663.         display.set_pen(temp_col)
  664.         display.circle(100+14*position,17,10)
  665.         display.set_pen(c2)
  666.         display.text("P",15,10,310,scale = 3)    
  667.         display.set_pen(whi)
  668.         display.text(str(position),60,10,310,scale = 2)
  669.  
  670. #==== Rot Enc Section =============
  671. def count_changed(count):
  672.     print("Count: ", count, sep="")
  673.     h = ((count % STEPS_PER_REV) * 360.0) / STEPS_PER_REV     # Convert the count to a colour hue
  674.     r, g, b = [int(255 * c) for c in hsv_to_rgb(h / 360.0, 1.0, 1.0)]  # rainbow magic
  675.     lights(r,g,b,-1)
  676.     r = int(r*BRIGHTNESS)
  677.     g = int(g*BRIGHTNESS)
  678.     b = int(b*BRIGHTNESS)
  679.     w = 0
  680.     for ptb in range(RING_NO):
  681.         ring[ptb] =(r,g,b,w)
  682.     ring.write()
  683.        
  684. def rot_enc():
  685.     display.set_pen(blk)
  686.     display.clear()
  687.     display.set_pen(whi)
  688.     display.text("Rotary Encoder",20,100,320,scale=4)
  689.     display.text("Turn the knob",20,180,320,scale=3)
  690.     display.update()
  691.     count = 0
  692.     count_changed(count)
  693.     enc.clear_interrupt_flag()
  694.  
  695.     colours = ["Red", "Light Red", "Orange", "Light Orange", "Yellow", "Lime", "Mid Green", "Bright Green", "Green",
  696.                "Acid Green", "Light Cyan", "Cyan", "Blue Green", "Mid Blue", "Light Blue", "Bright Blue", "Blue", "Pinky Blue",
  697.                "Bright Purple", "Mid-purple", "Magenta", "Bright Magenta", "Redish Magenta", "Blue Red"]
  698.        
  699.     print("\nTurn the Rotary Encoder\n")
  700.     oled.fill(0)
  701.     oled.text("Turn the Rotary",0,15,1)
  702.     oled.text("    Encoder",0,32,1)
  703.     oled.text("Button = MENU", 12,55,1)
  704.     oled.show()
  705.     lcd.clear()
  706.     lcd.putstr("Turn Rotary Encoder")
  707.     lcd.move_to(3,3)
  708.     lcd.putstr("Menu: Button")
  709.        
  710.     while ioe.input(ioe_button_pin) == 1:
  711.         if enc.get_interrupt_flag():
  712.             count = enc.read()
  713.             enc.clear_interrupt_flag()
  714.             while count < 0:
  715.                 count += STEPS_PER_REV
  716.             count_changed(count)
  717.             print("      " + colours[count % 24])
  718.             oled.fill(0)
  719.             gap = (128 - 8 * len(colours[count % 24]))// 2
  720.             oled.text(colours[count % 24],gap,25,1)
  721.             oled.text("  Button = HALT", 0,55,1)
  722.             oled.show()
  723.             display.set_pen(yel)
  724.             display.text(colours[count % 24],45,5,300,scale = 3)
  725.             print(colours[count % 24])
  726.             display.update()
  727.  
  728.     tidy_up()
  729. # End of Rot Enc ==============
  730.  
  731. # === TrackBall section=====
  732. def track_ball():
  733.     display.set_pen(blk)
  734.     display.clear()
  735.     display.set_pen(whi)
  736.     display.text("Track Ball",20,100,320,scale=4)
  737.     display.update()
  738.     oled.fill(0)
  739.     oled.show()
  740.     print("Roll the trackball to change colour!")
  741.     lcd.clear()
  742.     lcd.putstr("Track Ball")
  743.     lcd.move_to(0,1)
  744.     lcd.putstr("Roll the ball")
  745.     lcd.move_to(0,2)
  746.     lcd.putstr("Col: U/D Bright: L/R")
  747.     lcd.move_to(0,3)
  748.     lcd.putstr("Press ball to halt")
  749.     x = 0 # Controls Neopixel colours
  750.     y = 10 # Controls brightness
  751.     running2 = True
  752.     while running2:
  753.         state = trackball.read()
  754.         if state[BreakoutTrackball.SW_PRESSED]:
  755.             oled.fill(0)
  756.             running2 = False  # Out of loop at bottom
  757.         elif state[BreakoutTrackball.LEFT] > sensitivity:
  758.             oled.fill(0)
  759.             x = x + 1
  760.             if x == 8:
  761.                 x = 0
  762.         elif state[BreakoutTrackball.RIGHT] > sensitivity:
  763.             oled.fill(0)
  764.             x = x - 1
  765.             if x == -1:
  766.                 x = 7
  767.         elif state[BreakoutTrackball.UP] > sensitivity:
  768.             oled.fill(0)
  769.             y = y - 1
  770.             if y < 0:
  771.                 y = 0
  772.         elif state[BreakoutTrackball.DOWN] > sensitivity:
  773.             oled.fill(0)
  774.             y = y + 1
  775.             if y >10:
  776.                 y = 10
  777.         elif state[BreakoutTrackball.SW_CHANGED]:
  778.             pass
  779.         oled.text("x = "+str(x),20,40,1)
  780.         oled.text("y = "+str(y),20,55,1)
  781.         oled.text(col_names[x],0,20,1)
  782.         oled.fill_rect(100,62-y*6, 20, y*6, 1)   # draw a solid rectangle
  783.         for q in range(11):
  784.             if (q == 5) or (q == 10):
  785.                 oled.hline(90,62-q*6,15,1) # Longer central tick
  786.             else:    
  787.                 oled.hline(95,62-q*6,10,1)
  788.         oled.hline(90,62,30,1)
  789.         r,g,b = colours[x]
  790.         r = int(r /10 * y)
  791.         g = int(g /10 * y)
  792.         b = int(b /10 * y)
  793.         oled.text(str(r),0,5,1) # Current RGB values
  794.         oled.text(str(g),30,5,1)
  795.         oled.text(str(b),60,5,1)
  796.         lights(r,g,b,-1)            # Values/ bar graphs on Color Display
  797.         for i in range(NUM_LEDS):            
  798.             np[i] = (r,g,b)
  799.         np.write()
  800.         trackball.set_rgbw(r,g,b, 0)
  801.         r = int(r*BRIGHTNESS)
  802.         g = int(g*BRIGHTNESS)
  803.         b = int(b*BRIGHTNESS)
  804.         w = 0
  805.         for ptb in range(RING_NO):
  806.             ring[ptb] =(r,g,b,w)
  807.         ring.write()              
  808.         oled.show()
  809.         display.set_pen(whi)
  810.         display.text("Track Ball",50,5,200,scale = 3)
  811.         display.update()
  812.         display.update()
  813.         time.sleep(0.02)
  814.     tidy_up()
  815.  
  816. # =========== VOICE SYSTEM ==========
  817. def voice():
  818.     display.set_pen(blk)
  819.     display.clear()
  820.     display.set_pen(whi)
  821.     display.text("Voice Control",20,100,320,scale=4)
  822.     display.update()
  823.     SLEEP_SECONDS = 1
  824.     lcd.clear()
  825.     lcd.putstr("Voice Recognition")
  826.     lcd.move_to(0,1)
  827.     lcd.putstr("'Hello Robot'")
  828.     lcd.move_to(0,2)
  829.     lcd.putstr("Say a colour")
  830.     lcd.move_to(0,3)
  831.     lcd.putstr("'Stop' to HALT")
  832.     print('Speak your commands:')
  833.     running3 = True
  834.     while running3:
  835.         cmd_id = get_cmd_id(sensor=voice_sensor)
  836.  
  837.         if isinstance(cmd_id, int):
  838.             if cmd_id == 5: # Stop
  839.                 print("Stop")
  840.                 oled.fill(0)
  841.                 running3 = False
  842.                 oled.show()
  843.                 for i in range(NUM_LEDS):
  844.                     np[i] =(0,0,0) # Clear the strip
  845.                 np.write()
  846.                
  847.             elif (cmd_id < 5) or (cmd_id > 13): # Out of range cmds
  848.                 pass
  849.             else:
  850.                 p = cmd_id - 6
  851.                 print(col_names[p])
  852.                 oled.fill(0)
  853.                 oled.text(col_names[p], 0,0,1)
  854.                 oled.show()
  855.                 for i in range(NUM_LEDS):
  856.                     r,g,b = colours[p]
  857.                     np[i] =(r,g,b)
  858.                 np.write()
  859.                 enc.set_led(r,g,b)
  860.                 r2 = int(r * adj /2)
  861.                 g2 = int(g * adj /2)
  862.                 b2 = int(b * adj /2)
  863.                 # RGB LED
  864.                 ioe.output(rd, r2)
  865.                 ioe.output(green, g2)
  866.                 ioe.output(blue, b2)
  867.                 trackball.set_rgbw(r,g,b, 0)
  868.                 r3 = int(r*BRIGHTNESS)
  869.                 g3 = int(g*BRIGHTNESS)
  870.                 b3 = int(b*BRIGHTNESS)
  871.                 w3 = 0
  872.                 for ptb in range(RING_NO):
  873.                     ring[ptb] =(r3,g3,b3,w3)
  874.                 ring.write()
  875.                 display.set_pen(blk)
  876.                 display.clear()
  877.                 display.set_pen(col_p8[p])
  878.                 print(col_p8[p])
  879.                 display.text(col_names[p],20,100,320,scale=4)
  880.                 display.update()
  881.         time.sleep(SLEEP_SECONDS)
  882.     tidy_up()
  883.  
  884. # === Potentiometer control - 3 in Pico ADCs for RGB colours ===
  885. #                and 1 on IO Expansion for position
  886. def pots4():
  887.     display.set_pen(blk)
  888.     display.clear()
  889.     display.set_pen(whi)
  890.     display.text("4 Potentiometers",20,100,320,scale=4)
  891.     display.text("Turn the pots",20,180,320,scale=3)
  892.     display.update()
  893.     lcd.clear()
  894.     lcd.putstr("4 potentiometers")
  895.     lcd.move_to(0,1)
  896.     lcd.putstr("Twist the pots")
  897.     lcd.move_to(0,3)
  898.     lcd.putstr("Menu: Button")
  899.     oldpos = 0
  900.     oldtotal = 0
  901.     for i in range(NUM_LEDS):
  902.         np[i] = (0,0,0)
  903.     np.write()
  904.  
  905.     while ioe.input(ioe_button_pin) == 1:
  906.        
  907.         led.set_rgb(0, 0, 0)
  908.         oled.text("Turn the Pot",0,0,1)
  909.        
  910.         pot = ioe.input(ioe_adc_pin) // 4 # 10 bit resolution
  911.         pos = int(pot * 14 /1023) # Range 0 - 14
  912.  
  913.         r = get_pot_no(0,255)
  914.         g = get_pot_no(1,255)
  915.         b = get_pot_no(2,255)
  916.         r3 = int(r*BRIGHTNESS)
  917.         g3 = int(g*BRIGHTNESS)
  918.         b3 = int(b*BRIGHTNESS)
  919.         w3 = 0
  920.         lights(r,g,b,pos)        
  921.         display.update()
  922.         # Ring
  923.         for ptb in range(RING_NO):
  924.             ring[ptb] =(0,0,0,0)
  925.         ring[15-pos] = (r3,g3,b3,w3)
  926.         ring.write()
  927.         oled.text("Position: " + str(int(pos)),0,25,1)
  928.         total = r+g+b
  929.         if oldpos == pos and oldtotal == total:
  930.             pass
  931.         else:
  932.             np[oldpos] = (0,0,0)
  933.             oldpot = pos
  934.             oldtotal = total
  935.         np[pos] = (r,g,b)
  936.         np.write()
  937.        
  938.     tidy_up()
  939.  
  940. # ========================================
  941.  
  942. # === Zapper  - Aye Arr Remote and IR receiver =======
  943. def IR_zap():
  944.     display.set_pen(blk)
  945.     display.clear()
  946.     display.set_pen(whi)
  947.     display.text("IR Remote/Zapper",0,100,320,scale=4)
  948.     display.text("Press some buttons",20,180,320,scale=3)
  949.     display.update()
  950.     global running
  951.     lcd.clear()
  952.     lcd.putstr("IR Zapper Control")
  953.     lcd.move_to(0,1)
  954.     lcd.putstr("(0) - (9) Colours")
  955.     lcd.move_to(0,2)
  956.     lcd.putstr("(CCW)-(CW) = Spin")
  957.     lcd.move_to(0,3)
  958.     lcd.putstr("(OK_STOP) to HALT")
  959.  
  960.     # Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt)
  961.     try:
  962.         receiver.start()
  963.  
  964.         running = True
  965.         while running:
  966.             # Decode any IR pulses received since the last time this was called.
  967.             # This should be done as frequently as possible to avoid inputs feeling sluggish
  968.             receiver.decode()
  969.  
  970.     # End the program by stopping any active systems
  971.     finally:
  972.         receiver.stop()
  973.         for led in range(NUM_LEDS):
  974.             np[led] =(0,0,0)
  975.         np.write()
  976.         time.sleep(0.1)     # Short delay for the clear to take effect
  977.        
  978.     print("STOPPED")
  979.     tidy_up()
  980. # === End of zapper proc ==============
  981.  
  982. # ==== QUAKE Routine = Uses WiFi ==================
  983. def clean(): # Clear the screen to Black
  984.     display.set_pen(blk)
  985.     display.clear()
  986.     display.update()
  987.  
  988. # Routine to separate and extract data items from a single downloaded line
  989. def splitup(s):
  990.     string = ""
  991.     items = []
  992.  
  993.     for p in range(len(s)):
  994.         c = s[p]
  995. #        print(type(c))
  996.         if c != chr(124):
  997.             string = string + c
  998.         else:
  999.             items.append(string)
  1000.             string = ""
  1001.     items.append(string)        
  1002.  
  1003.     # Extract date and time from second item
  1004.     dt = items[1]
  1005.     date = dt[0:10]
  1006.     ttime = dt[11:19]
  1007.     return(items,date,ttime)
  1008.  
  1009. def quake():
  1010.     clean()
  1011.     display.set_pen(red)
  1012.     display.text("EarthQuake",80,120,300,3)
  1013.     '''
  1014.    display.set_pen(blu)
  1015.    display.text("Data from: https://earthquake.usgs.gov",70,400,480,2)
  1016.    display.text("Tony Goodhew, Leicester UK",120,450,480,2)
  1017.    '''
  1018.     display.update()
  1019.     lcd.clear()
  1020.     lcd.putstr("Earthquakes")
  1021.     lcd.move_to(0,3)
  1022.     lcd.putstr("Let it run: 0 - 9")
  1023.     time.sleep(1)
  1024.     display.set_pen(blk)
  1025.     clean()
  1026.     for p in range(35):    # Shake Title routine
  1027.         display.set_pen(blk)
  1028.         display.rectangle(60,75,200,100)
  1029.         xx = randint(0,16)-8
  1030.         yy = randint(0,16)-8
  1031.         display.set_pen(red)
  1032.         display.text("EarthQuake",80+xx,120+yy,300,3)
  1033.         display.update()
  1034.         time.sleep(0.07)
  1035.     clean()
  1036.     display.set_pen(red)
  1037.     display.text("EarthQuake",80,120,3,3)
  1038.     display.update()
  1039.     time.sleep(0.6)
  1040.  
  1041.     clean()
  1042.     display.set_pen(red)
  1043.     display.text("Connecting to WiFi",10,30,300,3)
  1044.     display.update()
  1045.  
  1046.     # Activate WiFi
  1047.     wlan = network.WLAN(network.STA_IF)
  1048.     wlan.active(True)
  1049.  
  1050.     wlan.connect(WIFI_SSID, WIFI_PASSWORD)
  1051.     max_wait = 30
  1052.     while max_wait > 0:
  1053.         if wlan.status() < 0 or wlan.status() >= 3:
  1054.             break
  1055.         max_wait -= 1
  1056.         print("Waiting for Wi-Fi connection...")
  1057.         display.set_pen(yel)
  1058.         display.text("Waiting for Wi-Fi connection...",10,70,300,3)
  1059.         display.update()
  1060.         time.sleep(1)
  1061.  
  1062.     if wlan.status() != 3:
  1063.         raise RuntimeError("Network connection failed")
  1064.     else:
  1065.         print("Connected to Wi-Fi network.")
  1066.         print(wlan.ifconfig())
  1067.  
  1068.     clean()
  1069.     display.set_pen(grn)
  1070.     display.text("Connected to WiFi",50,20,300,3)
  1071.     display.set_pen(yel)
  1072.     display.text("   Processing",70,60,300,3)
  1073.     display.update()
  1074.  
  1075.     # ===== Main section of Quake ====
  1076.  
  1077.     # Access EarthQuake website and get first 10 lines
  1078.     response = requests.get("https://earthquake.usgs.gov/fdsnws/event/1/query?format=text&limit=10")
  1079.  
  1080.     # Separate into lines
  1081.     lines = []
  1082.     for x in response.content.splitlines():
  1083.         xs = str(x)
  1084.     #        print(str(xs))
  1085.         lines.append(str(x))
  1086.     response.close()
  1087.  
  1088.     clean()
  1089.  
  1090.     events = []
  1091.     for i in range(1,11):    
  1092.         k = splitup(lines[i]) # This does the major lifting using the proc above
  1093.         events.append(k)
  1094.     '''
  1095.    # List of items for information
  1096.    names = ['EventID', 'Time', 'Latitude', 'Longitude', 'Depth/km', 'Author', 'Catalog', 'Contributor',
  1097.             'ContributorID', 'MagType', 'Magnitude', 'MagAuthor', 'EventLocationName', 'Date', 'Time']
  1098.    '''
  1099.  
  1100.     # Show recent event high-lights
  1101.     for i in range(10):
  1102.         clean()
  1103.         display.set_pen(cyn)
  1104.            
  1105.         k,date,ttime = events[i] # Fetch decoded quake data line
  1106.  
  1107.         display.text(date + "  --  " + ttime,30,0,460,2)
  1108.         display.set_pen(yel)
  1109.         place = k[12]
  1110.         place = place[:-1]  # remove final quote character
  1111.         display.text(place,0,40,290,2)
  1112.         lat = round(float(k[2]),3)
  1113.         long = round(float(k[3]),3)
  1114.         display.text("Lat/Lon: "+str(lat) + " "+ str(long),0,80,300,2)
  1115.         display.set_pen(grn)
  1116.         display.text("Magnitude: " + k[10],0,120,300,2)
  1117.         display.text("Type: " + k[9],0,140,300,2)
  1118.         deep = round(float(k[4]),3)
  1119.         display.text("Depth/km: "+ str(deep),0,160,300,2)
  1120.         display.set_pen(yel)
  1121.         display.text(str(i),300,190,100,4)
  1122.         display.update()
  1123.  
  1124.         time.sleep(3)
  1125.     clean()
  1126.     lcd.clear()
  1127.     print("\nDone")
  1128.  
  1129. # ================ End of QUAKE =================
  1130.  
  1131. # ==== Menu system on Qw/ST Pad - U, D, R  and SSD1306 ====
  1132. def show_menu(p,maxx):
  1133.     maxx = len(items) -2
  1134.     oled.fill(0)
  1135.     oled.text(">",0,30,1)
  1136.     oled.text(items[p-1],15,10,1)
  1137.     oled.text(items[p],15,30,1)
  1138.     oled.text(items[p+1],15,50,1)
  1139.     oled.show()
  1140.    
  1141. def menu():
  1142.     maxl = len(items) -2
  1143.     p = 2
  1144.     show_menu(p,maxl)
  1145.     while True:
  1146.         buttons = qwstpad.read_buttons()
  1147.         if buttons['R']:
  1148.             while buttons['R']:
  1149.                 buttons = qwstpad.read_buttons()
  1150.             return p
  1151.         elif buttons['U']:
  1152.             p = p - 1
  1153.             if p <= 1:
  1154.                 p = 1
  1155.             show_menu(p,maxl)
  1156.             while buttons['U']:
  1157.                 buttons = qwstpad.read_buttons()
  1158.         elif buttons['D']:
  1159.             p = p + 1
  1160.             if p >= maxl:
  1161.                 p = maxl
  1162.             show_menu(p,maxl)
  1163.             while buttons['D']:
  1164.                 buttons = qwstpad.read_buttons()
  1165.         else:
  1166.             pass
  1167.  
  1168. #====== MAIN PROGRAM ======
  1169. tidy_up()
  1170. global items
  1171. items = (" ","Track Ball", "Rotary Encoder","Sensing","4 Pots","IR Zapper","Voice",
  1172.          "Quake-WiFi","STOP"," ")
  1173. run2 = True
  1174. while run2:
  1175.     lcd.clear()
  1176.     lcd.putstr("Menu on SSD1306")
  1177.     lcd.move_to(0,1)
  1178.     lcd.putstr("Use U,D and R")
  1179.     lcd.move_to(0,2)
  1180.     lcd.putstr("on QW/ST Pad")
  1181.     q = menu()   # Get value from menu system
  1182.     if   q == 1: track_ball() # Track Ball
  1183.     elif q == 2: rot_enc()    # Rotary Encoder
  1184.     elif q == 3: sensing()    # Sensor stick
  1185.     elif q == 4: pots4()      # IO Expander  
  1186.     elif q == 5: IR_zap()     # AYE ARR remote    
  1187.     elif q == 6: voice()      # Voice recognition
  1188.     elif q == 7: quake()      # WiFi
  1189.     elif q == 8: run2 = False # STOP
  1190.     else: pass
  1191.  
  1192. tidy_up()
  1193.  
  1194.  
  1195.  
Tags: i2c pi pico
Advertisement
Comments
  • TonyGo
    58 days
    # text 0.20 KB | 0 0
    1. Full details of the project can be found on the Pimoroni.com website.
    2. https://blog.pimoroni.com/tonys-big-i2c-project/
    3. and
    4. https://forums.pimoroni.com/t/a-big-i-c-project/28891/4
    5.  
    6. I hope you like it.
Add Comment
Please, Sign In to add comment