adc_pin = AnalogIn(board.D0) dac_pin = AnalogOut(board.A0) # setup initial state # ADC adc_running = False adc_delay = 1.0 adc_mode = "raw" # DAC dac_running = False dac_level = 30000 dac_pin.value = 0 # LED pixels = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=.95) black = (0, 0, 0) curColor = black targetColor = black led_mode = "off" pixels.fill(black) pixels.show() # Timer
# Assignment 1 Led Fade import board from analogio import AnalogOut import time import neopixel yeet = 0 #Power yote = 1 #Bool pin = 13 #Pin analog_out = AnalogOut(board.A0) while True: if (yote == 1): # fade in yeet += 10 if (yote == 0): yeet -= 10 # fade out if (yeet >= 65000): yote = 0 if (yeet <= 0): # range of light yote = 1 analog_out.value = yeet
# CircuitPython IO demo - analog output from analogio import AnalogOut import board analog_out = AnalogOut(board.A0) while True: # Count up from 0 to 65535, with 64 increment # which ends up corresponding to the DAC's 10-bit range for i in range(0, 65535, 64): analog_out.value = i
# Trinket IO demo - analog output import board from analogio import AnalogOut aout = AnalogOut(board.D1) while True: # Count up from 0 to 65535, with 64 increment # which ends up corresponding to the DAC's 10-bit range for i in range(0, 65535, 64): aout.value = i
# sendMeasurement(str(getTemp(temp1))) elif command == COMMAND_DICT['temp2']: sendMeasurement(str(temp2Value)) elif command == COMMAND_DICT['set-current']: MODE = 'current' targetCurrent = int.from_bytes(uart.read(header), 'big') / 1000 output = int(targetCurrent * 2**16 * 14.7 / 5 / 3.3) print("Set current to {}".format(targetCurrent)) elif command == COMMAND_DICT['set-power']: MODE = 'power' targetPower = int.from_bytes(uart.read(header), 'big') / 1000 else: if watchdog > 10: print("Watchdog") targetCurrent = 0 else: watchdog += 1 if battValue > 0.1: faultLed.value = False if MODE == 'power': targetCurrent = targetPower / battValue error = int((targetCurrent - currentValue) * 2**16 / 3.3) output += error // 4 mos.value = min(max(output, 0), 2**16 - 1) else: faultLed.value = True
######################### MAIN LOOP ############################## i = 0 while True: # spin internal LED around! autoshow is on dot[0] = wheel(i & 255) # also make the neopixels swirl around for p in range(NUMPIXELS): idx = int ((p * 256 / NUMPIXELS) + i) neopixels[p] = wheel(idx & 255) neopixels.show() # set analog output to 0-3.3V (0-65535 in increments) aout.value = i * 256 # Read analog voltage on D0 print("D0: %0.2f" % getVoltage(analog1in)) # use D3 as capacitive touch to turn on internal LED if touch.value: print("D3 touched!") led.value = touch.value if not button.value: print("Button on D2 pressed!") # optional! uncomment below & save to have it sent a keypress #kbd.press(Keycode.A) #kbd.release_all()
import adafruit_ssd1306 # OLED wing import neopixel as neo # on-board NeoPixel import microcontroller # for checking CPU temperature import gc # for checking memory capacity # ### Setup ### i2c = busio.I2C(board.SCL, board.SDA) oled = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c) oled.fill(0) oled.show() # analog inputs and meter output probe_pin = AnalogIn(board.A4) test_pin = AnalogIn(board.A3) meter_pin = AnalogOut(board.A0) meter_pin.value = 0 # Position the meter to zero # on-board activity led = digitalio.DigitalInOut(board.D13) led.direction = digitalio.Direction.OUTPUT led.value = True # GPIO for pwm indicators # neg_led = pulseio.PWMOut(board.D5) # negative red LED # pos_led = pulseio.PWMOut(board.D6) # positive green LED amber_led = pulseio.PWMOut(board.D9) # absolute value amber LED amber_led.duty_cycle = 32000 # turn on amber LED for general illumination # piezo speaker (PWM output) piezo = pulseio.PWMOut(board.D10, duty_cycle=0,
triggerOut.value = 65535 for i in range(randint(3, 5)): MakeRedLeft() MakeBlueRight() pixels.show() time.sleep(0.02) MakeBlueLeft() MakeRedRight() pixels.show() time.sleep(0.02) # TurnOffPixels() for i in range(randint(3, 5)): for p in range(randint(1, 9)): pixels[randint(0, 9)] = (255, 255, 255) pixels.show() time.sleep(0.02) TurnOffPixels() while True: voltage = GetVoltage(triggerIn) if (rightButton.value): print("Right button pressed (OFF)") triggerOut.value = 0 elif (voltage > 2.5): print("Voltage: " + str(voltage) + " (ON)") LightPixels(True) elif (leftButton.value): print("Left button pressed (ON)") LightPixels(False)
import time import board from digitalio import DigitalInOut, Direction, Pull from analogio import AnalogOut direction_pin = DigitalInOut(board.D0) direction_pin.direction = Direction.OUTPUT analog_out = AnalogOut(board.A0) while True: time.sleep(1) print("hey") direction_pin.value = False analog_out.value = 43690 time.sleep(0.01) analog_out.value = 0
import board #libraries from analogio import AnalogOut analog_out = AnalogOut(board.A0) #setup LED abc = 1 #variables power = 0 speed = 3 while True: #repeat if(abc): power += speed #power goes up else: power -= speed #and also down if(power >= 65000): abc = 0 if(power <= 0): #this is the thing that decides whether power goes up or down abc = 1 analog_out.value = power #run power through the LED
import pulseio from analogio import AnalogIn, AnalogOut import board import time from simpleio import map_range import adafruit_dotstar as dotstar # Trinket import microcontroller # for checking CPU temperature import gc # for checking memory capacity # ### Setup ### # analog inputs and meter output probe_pin = AnalogIn(board.A4) test_pin = AnalogIn(board.A2) meter_pin = AnalogOut(board.A0) meter_pin.value = 0 # Position the meter to zero # on-board activity indicator (when moving the meter needle) led = digitalio.DigitalInOut(board.D13) led.direction = digitalio.Direction.OUTPUT # GPIO for pwm indicators # neg_led = pulseio.PWMOut(board.D3) # negative red LED # pos_led = pulseio.PWMOut(board.D4) # positive green LED amber_led = pulseio.PWMOut(board.D3) # absolute value amber LED amber_led.duty_cycle = 65535 # turn on amber LED for general illumination # on-board DotStar; low brightness dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.1) dot[0] = [64, 0, 0] # display red
# ## Helpers ## # (none) # ### Set Initial Parameters ### # (none) print("2018-09-04 Simple Retro CV Meter v00.py") print("GC.mem_free: ", gc.mem_free()) print("CPU.freqency: ", microcontroller.cpu.frequency) print("CPU.temperature: ", microcontroller.cpu.temperature) # print("Battery voltage: ", AnalogIn(board.Ax) ) # not used # Gradually center (zero) the meter's output before reading the input voltage. for i in range(0, 32768): meter_pin.value = i time.sleep(0.500) # hold at center scale for 0.500 seconds # ### Main Loop ### while True: # Read the CV input and map to a +/-10V value. # Because of the input op-amp's signal inversion and fixed gain, a 0V # input to the Trinket's analog pin correlates to a CV input value of +10V; # a 3.3V input maps to a value of -10V. DO NOT adjust these values. cv_input_volt = map_range(cv_pin.value, 0, 65535, +10, -10) # Show the input voltage polarity on the DotStar indicator. if cv_input_volt > +1.0: # 1V noise threshold dot[0] = (0, 255, 0) # grn = positive neg_led.value = False zero_led.value = False
import board import time from analogio import AnalogOut led = AnalogOut(board.A0) inc = 32 val = 0 def clamp(n, minn, maxn): return max(min(maxn, n), minn) while True: if val+inc >= 65535 or val+inc < 0: inc = -inc clamp(val, 0, 65535) val = val + inc led.value = val
dial.show() barrel.show() dial_disp() # Main loop while True: reading = pot_read.value val = (reading * 500.0) / 65536 get_mode(val) phase += 1 last_hallstate = hallstate hallstate = sensor.value if not trigger.value and not sensor.value and not audio.playing: # If trigger is pulled while the barrel is closed if trigger_count < 20: galv_out.value = 7000 audio.play(shoot) galv_out.value = 0 elif ct < 4: galv_out.value = 0 bad_fire(ct) ct += 1 else: ct = 0 trigger_count += 1 elif hallstate and hallstate != last_hallstate: galv_out.value = 7000 audio.play(reloadOpen) elif not hallstate and hallstate != last_hallstate: trigger_count = 0 audio.play(reloadClose)
# extra ground for motor board motorGnd = DigitalInOut(board.D0) motorGnd.direction = Direction.OUTPUT motorGnd.value = 0 #print("STARTING PURRTY CAT") PURR_INCREMENT = 25 PURR_DECREMENT = 200 PURR_MINIMUM = 175 * 256 PURR_MAXIMUM = 185 * 256 # must have space for 16 bit value purrValue = 0 while True: if touch.value: if purrValue < PURR_MINIMUM: purrValue = PURR_MINIMUM purrValue += PURR_INCREMENT else: purrValue -= PURR_DECREMENT if purrValue < 0: purrValue = 0 if purrValue > PURR_MAXIMUM: purrValue = PURR_MAXIMUM # set analog output to 0-3.3V (0-65535 in increments) aout.value = purrValue # print("Touch {} , Purr {}".format(touch.raw_value, purrValue/256)) time.sleep(0.1) # make bigger to slow down #print("EXITING PURRTY CAT")