From 8e8d86147399b917d6955addff323a257f372fcb Mon Sep 17 00:00:00 2001
From: schneider <schneider@blinkenlichts.net>
Date: Wed, 21 Aug 2019 18:15:52 +0200
Subject: [PATCH] feat(apps): Add scope to preload

---
 preload/apps/scope/__init__.py   | 35 ++++++++++++++++++++++++++++++++
 preload/apps/scope/metadata.json |  1 +
 2 files changed, 36 insertions(+)
 create mode 100644 preload/apps/scope/__init__.py
 create mode 100644 preload/apps/scope/metadata.json

diff --git a/preload/apps/scope/__init__.py b/preload/apps/scope/__init__.py
new file mode 100644
index 00000000..b541d2c2
--- /dev/null
+++ b/preload/apps/scope/__init__.py
@@ -0,0 +1,35 @@
+import os
+import display
+import utime
+import buttons
+import light_sensor
+import math
+
+WIDTH=160
+HEIGHT=80
+
+disp = display.open()
+
+light_sensor.start()
+
+history = []
+
+while True:
+    disp.clear()
+    
+    value = light_sensor.get_reading()
+    
+    history.insert(0, value)
+    if len(history) > WIDTH:
+        history.pop()
+
+    disp.print("%i"%value)
+    
+    for i in range(0,len(history)):
+        # Rescale to range 0 <= value < HEIGHT-1
+        y = math.floor(history[i]*(HEIGHT-2)/max(history))
+        
+        disp.pixel(WIDTH-i, HEIGHT-y-1)
+    
+    disp.update()
+    utime.sleep(0.1)
\ No newline at end of file
diff --git a/preload/apps/scope/metadata.json b/preload/apps/scope/metadata.json
new file mode 100644
index 00000000..821fd3bf
--- /dev/null
+++ b/preload/apps/scope/metadata.json
@@ -0,0 +1 @@
+{"name":"Scope","description":"A very simple egg that reads the light sensor and displays its raw value and a scope. Will be extended to other ADC channels once we have the firmware ready.","category":"hardware","author":"koalo","revision":1}
\ No newline at end of file
-- 
GitLab