Uncategorized

pico program

# digi_io_v13 tlfong01 2021mar04hkt2219
# Piromoni Tiny2040

# *** Contents ***
# 01 Import machine, Pin, time
# 02 Digital output and LED pin functions
# 03 Digital input and button pin functions

# *** Import  ***
from machine import Pin
import time

# *** Logical/time/repetition variable/constant declarations ***

lowValue  = 0
highValue = 1

onValue   = lowValue  # On board RGB led = Low active 
offValue  = highValue

highTime  = 0.5 # seconds
lowTime   = 0.5 # seconds

onTime    = lowTime  # Led on time
offTime   = highTime # Led off time

totalCount = 2 # Repeat twice

# *** Digital output/LED pin configuration ***

# RGB led pin num ***
redLedPinNum     = 18
greenLedPinNum   = 19
blueLedPinNum    = 20

rgbLedPinNumList = [redLedPinNum, greenLedPinNum, blueLedPinNum] 

# *** Digital ouput Led pin functions ***

def initDigiOutPinNumList(digiOutPinNumList):
    print('Begin initDigiOutPinNumList(), ...')
    for digiOutPinNum in digiOutPinNumList:
        digiOutPin = Pin(digiOutPinNum, Pin.OUT)
        digiOutPin.value(onValue)
        time.sleep(onTime)
        digiOutPin.value(offValue)
    print('End   initDigiOutPinNumList().')
    return

def initLedPinNumList(ledPinNumList):
    print('Begin initLedPinNumList')
    initDigiOutPinNumList(ledPinNumList)
    print('End   initLedPinNumList')        
    return

def blinkLedPinNumList(ledPinNumList, onTime, offTime, countTotal):
    print('Begin blinkLedPinNumList')
    
    # *** Init ***
    ledPinList = []
    for ledPinNum in ledPinNumList:
        ledPin = Pin(ledPinNum, Pin.OUT)
        ledPin.value(offValue)         
        ledPinList.append(ledPin)
    
    #*** Blink ***
    for count in range(countTotal):        
        for ledPin in ledPinList:
            ledPin.value(onValue)
            time.sleep(onTime)
            ledPin.value(offValue)
            time.sleep(offTime)        
        
    print('End   blinkLedPinNumList')        
    return

def toggleDigiOutPinNumList(digiOutPinNumList, lowTime, highTime, countTotal):
    print('Begin toggleDigiOutpPinNumList(),...')
    
    # *** Init digiOutPinList ***
    digiOutPinList = []
    for digiOutPinNum in digiOutPinNumList:
        digiOutPin = Pin(digiOutPinNum, Pin.OUT)
        digiOutPin.value(offValue)         
        digiOutPinList.append(digiOutPin)
    
    #*** Toggle ***
    for count in range(countTotal):        
        for digiOutPin in digiOutPinList:
            digiOutPin.value(lowValue)
            time.sleep(lowTime)
            digiOutPin.value(highValue)
            time.sleep(highTime)        

    print('End   toggleDigiOutpPinNumList().')           
    return

# *** Digital Input Pins *** 

# *** Boot/Select button pin config ***

# *** Button state varaibles and constants ***

buttonNotPressed = True
buttonPressed    = False

# *** Button config ***

bootSelectPinNum = 23

bootSelectButtonPin = Pin(bootSelectPinNum, Pin.IN, Pin.PULL_DOWN)

def readBootSelectButton():
    print('\nBegin readBootSelectButton(),...')    
    print('  Press and hold 0.5 second Button pin 14 to toggle LED pin 15, <Ctrl F2> to exit program.')    
    for count in range(10):
        print('    count =', count, end = '')
        if bootSelectButtonPin.value() == buttonNotPressed:
            print('  Button not pressed, ...')
        else:
            #led.toggle()
            print('  Button     pressed, ...')
        time.sleep(1)
    print('End   readBootSelectButton(),...')        
    return

# *** main ***

#initLedPinNumList(rgbLedPinNumList)

toggleDigiOutPinNumList([18, 19, 20], 0.25, 0.5, 1) 
readBootSelectButton()

# End ***

# *** Sample Output - tlfong01  2021feb10hkt2043 ***

'''
>>> %Run -c $EDITOR_CONTENT
Begin toggleDigiOutpPinNumList(),...
End   toggleDigiOutpPinNumList().
>>> 
'''
# *** End of sample output ***









Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.