Browse Source

added default values to config

subDesTagesMitExtraKaese 3 years ago
parent
commit
f26ac0d7ce
5 changed files with 13 additions and 12 deletions
  1. 2 1
      .vscode/settings.json
  2. 1 1
      boot.py
  3. 6 6
      config.py
  4. 1 1
      leds.py
  5. 3 3
      main.py

+ 2 - 1
.vscode/settings.json

@@ -10,5 +10,6 @@
     "python.linting.pylintEnabled": true,
     "python.analysis.extraPaths": [
       "./.micropy/BradenM-micropy-stubs-70f5531/stubs"
-    ]
+    ],
+    "python.languageServer": "Microsoft"
 }

+ 1 - 1
boot.py

@@ -9,7 +9,7 @@ try:
   from config import LED_LIST
   for i in range(len(LED_LIST)):
     pin = machine.Pin(LED_LIST[i][1], machine.Pin.OUT, machine.Pin.PULL_DOWN)
-    machine.PWM(pin, channel=LED_LIST[i][2], freq=800, duty=100 if i in [0, 4] else 0)
+    machine.PWM(pin, channel=LED_LIST[i][2], freq=800, duty=LED_LIST[i][3])
 
   import network
 

+ 6 - 6
config.py

@@ -8,11 +8,11 @@ CLIENT_ID = ubinascii.hexlify(machine.unique_id())
 TOPIC_SUB = b"Room/rgbBulb/1/command"
 TOPIC_PUB = b"Room/rgbBulb/1/state"
 
-#LEDs with name, pin and channel
+#LEDs with name, pin, channel and default value
 LED_LIST = [
-  ('R', machine.Pin.PA_05, 0),
-  ('G', machine.Pin.PB_13, 1),
-  ('B', machine.Pin.PB_15, 3),
-  ('C', machine.Pin.PB_16, 2),
-  ('W', machine.Pin.PB_08, 4)
+  ('R', machine.Pin.PA_05, 0, 100),
+  ('G', machine.Pin.PB_13, 1,   1),
+  ('B', machine.Pin.PB_15, 3,   1),
+  ('C', machine.Pin.PB_16, 2,   1),
+  ('W', machine.Pin.PB_08, 4, 100)
 ]

+ 1 - 1
leds.py

@@ -7,7 +7,7 @@ class Leds:
   def __init__(self):
     self.led_count = len(LED_LIST)
     self.pwm = [None] * self.led_count
-    self.vals = [0] * self.led_count
+    self.vals = [x[3] for x in LED_LIST]
     self.diff = [0] * self.led_count
     self.stepId = [0] * self.led_count
     self.steps = 50

+ 3 - 3
main.py

@@ -13,7 +13,6 @@ import gc
 gc.collect()
 
 leds = Leds()
-leds.setColor(2, 1)
 leds.update()
 
 station = network.WLAN(network.STA_IF)
@@ -40,7 +39,8 @@ def sub_cb(topic, msg):
     if 'speed' in cmd:
       leds.setSteps(int(cmd['speed']))
     if 'color' in cmd:
-      for i, (color, _, _) in enumerate(LED_LIST):
+      for i in range(len(LED_LIST)):
+        color = LED_LIST[i][0]
         if color in cmd['color']:
           leds.setColor(i, int(cmd['color'][color]))
     if 'reset' in cmd:
@@ -86,7 +86,7 @@ try:
     time.sleep(0.02)
     if station.isconnected() == False:
       leds.setColor(0, 60)
-except:
+except Exception as e:
   try:
     send_status("loop error")
   except: