From d6f4f7b6a4bb9d6f60b6d5a1d892d9f5df5011b8 Mon Sep 17 00:00:00 2001 From: Colton Padden Date: Wed, 19 Jun 2019 21:37:49 -0400 Subject: [PATCH 1/3] Example of using TouchPad for Upload --- main~.py | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/main~.py b/main~.py index d9cad79..ee1e195 100644 --- a/main~.py +++ b/main~.py @@ -4,28 +4,21 @@ # Copyright (c) 2019 F. Pascal Girard import machine -from machine import Timer +from machine import Timer, TouchPad, Pin -""" -# ESP32 Code - see below -# from machine import TouchPad -pad = TouchPad(Pin(14)) -""" -timer = Timer(0) -upgrade = False +TIMER_0 = Timer(0) -print("Running main") - - -def callback(pin): - global upgrade - upgrade = True - return upgrade +# TODO: get values from configuration file +# Touch value is around 500-600 when untouched, and 10-20 when touched +TOUCH_PAD = TouchPad(Pin(14)) +TOUCH_THRESHOLD = 50 def run(timer): - if not upgrade: + + # When the touch value is above the threshold, then it is not being touched + if TOUCH_PAD.read() > TOUCH_THRESHOLD: print("Running sensors...") import wake @@ -48,14 +41,4 @@ def run(timer): else: # an opportunity to enter WebREPL after hard reset print("Hard reset") - # ESP8266 Code - """ - pin0 = Pin(0, Pin.IN, Pin.PULL_UP) # set GPIO0 as input with pullup - pin0.irq(trigger=Pin.IRQ_RISING, handler=callback) - """ - # ESP32 Code - """ - """ - timer.init(period=5000, mode=Timer.ONE_SHOT, callback=run) - - # ESP32 Code + TIMER_0.init(period=5000, mode=Timer.ONE_SHOT, callback=run) From bd34138829223a80d0c21d8849c22513076f3814 Mon Sep 17 00:00:00 2001 From: Colton Padden Date: Mon, 1 Jul 2019 14:54:13 -0400 Subject: [PATCH 2/3] Moved TouchPad Parameters to Config --- config-generic.py | 4 ++++ main~.py | 16 ++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/config-generic.py b/config-generic.py index 7a210f7..a2127ad 100644 --- a/config-generic.py +++ b/config-generic.py @@ -27,3 +27,7 @@ # Sleep time for wake/sleep cycle in milliseconds SLEEP = 60 * 1000 + +# Capacitive Touch Parameters +TOUCH_PIN = 14 +TOUCH_THRESHOLD = 100 diff --git a/main~.py b/main~.py index ee1e195..2fe4e0e 100644 --- a/main~.py +++ b/main~.py @@ -5,26 +5,26 @@ import machine from machine import Timer, TouchPad, Pin +from config import TOUCH_PIN, TOUCH_THRESHOLD TIMER_0 = Timer(0) - -# TODO: get values from configuration file -# Touch value is around 500-600 when untouched, and 10-20 when touched -TOUCH_PAD = TouchPad(Pin(14)) -TOUCH_THRESHOLD = 50 +TOUCH_PAD = TouchPad(Pin(TOUCH_PIN)) def run(timer): + touch_value = TOUCH_PAD.read() + print("Touch Value: {}, Touch Threshold {}".format(touch_value, TOUCH_THRESHOLD)) + # When the touch value is above the threshold, then it is not being touched - if TOUCH_PAD.read() > TOUCH_THRESHOLD: - print("Running sensors...") + if touch_value > TOUCH_THRESHOLD: + print("Running Sensors...") import wake wake.main() else: - print("Upgrading...") + print("Starting AP and Web REPL...") import webrepl import iot From e0637d5fba460e5d6bec7ad770bf78a0fd755234 Mon Sep 17 00:00:00 2001 From: Colton Padden Date: Mon, 1 Jul 2019 20:06:00 -0400 Subject: [PATCH 3/3] Renamed main~.py to main.py --- main~.py => main.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename main~.py => main.py (100%) diff --git a/main~.py b/main.py similarity index 100% rename from main~.py rename to main.py