TinyCircuits Forum

General Category => User Projects / Code Examples => Topic started by: htmlgames on January 30, 2024, 05:54:14 PM

Title: Can we post .py code files here, or should they be git hosted?
Post by: htmlgames on January 30, 2024, 05:54:14 PM
Hi just wondered if ok as created my first (small) program for thumby today?

Edit: seen codei in other threads so guess ok.


below is a fun torch project.
Title: Re: Can we post .py code files here, or should they be git hosted?
Post by: htmlgames on January 30, 2024, 06:07:57 PM
Code: [Select]
import thumby

thumby.display.setFPS(2) # frames per second
brightness = 127
colour = 0 # black
torch = 1 # white 'ON'
blink = 0

while(not(thumby.buttonA.pressed() and thumby.buttonB.pressed())):
   
    if thumby.buttonA.justPressed():
        torch = 1
   
    if thumby.buttonB.justPressed():
        torch = 0
   
    if thumby.buttonL.pressed():
        blink = 0
        torch = 1
   
    if thumby.buttonR.pressed():
        blink = 1
        torch = torch
   
    if blink == 1:
        torch = not(torch)
   
    thumby.display.fill(torch) # fill screen with pixels
   
    if torch > 0:
       
        if thumby.buttonU.pressed():
            #colour = 1
           
            if brightness <= 120:
                brightness += 7
               

                thumby.display.drawText("increasing", 6, 4, colour)
                thumby.display.drawText("%d" % brightness, 6, 20, colour)
                thumby.audio.playBlocking(brightness * 7,42)
               
        if thumby.buttonD.pressed():
            #colour = 0
           
            if brightness > 8:
                brightness -= 7
               

                thumby.display.drawText("decreasing", 6, 4, colour)
                thumby.display.drawText("%d" % brightness, 6, 20, colour)
                thumby.audio.playBlocking(brightness * 7,42)
   
    thumby.display.brightness(brightness)
    thumby.display.update()