Skip to content

Commit

Permalink
day night bypass (#16)
Browse files Browse the repository at this point in the history
* functional grounding test

* added day and night cycle

* daily cycle
  • Loading branch information
baidarka authored Dec 9, 2023
1 parent 0ce7c7b commit 053512d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 45 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ E.g. Thonny or VSCode.

For lookenspeepers, build this project and watschen der Blinkenlichten!

- Wire up your RaspberryPi Pico according to the Fritzing diagram.
- Wire up your RaspberryPi Pico according to the Fritzing diagram
- Optionally remove the resistor on GPIO2 to use an 8 minutes day/night cycle
- Save the script 'slag-in-de-rondte.py' to your Pico as 'main.py'
- Restart your Pico

Expand Down Expand Up @@ -78,16 +79,16 @@ A hollow pipe tool (Dutch: holpijp) is only needed if you want to punch holes in

![Hollow pipe tool](/img/holpijp.png)

| pin | pin name | in/out | description |
| --- | --- | --- | --- |
| 3 | GND | | ground |
| 4 | GPIO 2 | in | (future use) |
| 21 | GPIO 16 | out 3.3V | LED Texel |
| 22 | GPIO 17 | out 3.3V | LED Vlieland |
| 24 | GPIO 18 | out 3.3V | LED Terschelling |
| 25 | GPIO 19 | out 3.3V | LED Ameland |
| 26 | GPIO 20 | out 3.3V | LED Schiermonnikoog |
| 39 | VSYS | 5V | LED Red + Green Harlingen |
| pin | pin name | in/out | description |
| --- | --- | --- | --- |
| 3 | GND | | ground |
| 4 | GPIO 2 | in | disables night and day cycle |
| 21 | GPIO 16 | out 3.3V | LED Texel |
| 22 | GPIO 17 | out 3.3V | LED Vlieland |
| 24 | GPIO 18 | out 3.3V | LED Terschelling |
| 25 | GPIO 19 | out 3.3V | LED Ameland |
| 26 | GPIO 20 | out 3.3V | LED Schiermonnikoog |
| 39 | VSYS | 5V | LED Red + Green Harlingen |

CAUTION:
Drawing too much power from the board may damage the board.
Expand Down
70 changes: 36 additions & 34 deletions slag-in-de-rondte.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
ameland = PWM(Pin(19), f)
schiermonnikoog = PWM(Pin(20), f)

# WIP: Optionally, run without day&night cycle
always_on = Pin(2, Pin.IN)

# Optionally, grab the temperature of your board
adc = machine.ADC(4)
# Optionally, run without night_n_day cycle
# - pin not grounded = night and day cycle of 8 minutes
# - pin grounded = continuously use LEDs
night_n_day = Pin(2, Pin.IN, Pin.PULL_UP)

# Coroutine: Flash a LED, once
async def flash(pwm):
Expand Down Expand Up @@ -92,7 +91,7 @@ async def isophase(pwm, d):
pwm.duty_u16(0)
await uasyncio.sleep_ms(round(d/2) * 1000)

# Corouting: Fade out a LED
# Corouting: Fade out a LED, to stop a cycle for the day
async def fade_out(pwm):

# Get the current duty cycle and fade out from there.
Expand Down Expand Up @@ -189,46 +188,49 @@ async def main():
# Half a day contains roughly a tidal cycle, high water + low water
# In the board game this cycle takes 8 minutes (480 seconds)
tidal_cycle = 480

# Switch on all lighthouses (night)
lighthouses = [
uasyncio.create_task(characteristics_texel(texel)),
uasyncio.create_task(characteristics_vlieland(vlieland)),
uasyncio.create_task(characteristics_terschelling(terschelling)),
uasyncio.create_task(characteristics_ameland(ameland)),
uasyncio.create_task(characteristics_schiermonnikoog(schiermonnikoog))
]

while True:

# A night of sailing starts. Switch on all five lighthouses
print('Night')
task_tx = uasyncio.create_task(characteristics_texel(texel))
task_vl = uasyncio.create_task(characteristics_vlieland(vlieland))
task_ts = uasyncio.create_task(characteristics_terschelling(terschelling))
task_am = uasyncio.create_task(characteristics_ameland(ameland))
task_sch = uasyncio.create_task(characteristics_schiermonnikoog(schiermonnikoog))


# Leave lighthouses on for the night
await uasyncio.sleep(tidal_cycle)

# Is Pin4 grounded?
# WORK IN PROGRESS; this seems like a bad approach
if always_on == 0:
# pin is grounded
print('always on!')
# Enable night_n_day cycle? (is Pin grounded?)
if night_n_day.value() == 0:
print('pin grounded: no night_n_day')
continue
else:
print('night & day')

# Print the temperature. (keep an eye on the board)
ADC_voltage = adc.read_u16() * (3.3/65536)
temp_celcius = 27 - (ADC_voltage - 0.706)/0.001721
print('Temperature: {}'.format(round(temp_celcius)))
print('pin not grounded: night_n_day')

# After a night of sailing comes... a day of sailing :)
# Switch off all five lighthouses
print('Day')
task_tx.cancel()
task_vl.cancel()
task_ts.cancel()
task_am.cancel()
task_sch.cancel()

print('day')
for task in lighthouses:
task.cancel()

# Run the GC
gc.collect()

## Leave lighthouses off for the day
# Leave lighthouses off for the day
await uasyncio.sleep(tidal_cycle)

# Switch the lighthouses on for the night
print('night')
lighthouses = [
uasyncio.create_task(characteristics_texel(texel)),
uasyncio.create_task(characteristics_vlieland(vlieland)),
uasyncio.create_task(characteristics_terschelling(terschelling)),
uasyncio.create_task(characteristics_ameland(ameland)),
uasyncio.create_task(characteristics_schiermonnikoog(schiermonnikoog))
]

# Start event loop
uasyncio.run(main())

0 comments on commit 053512d

Please sign in to comment.