summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2021-12-18 11:56:18 +0200
committerYuval Adam <_@yuv.al>2021-12-18 11:56:18 +0200
commit608e3ef1bc4f8d5b06f3ad6e56a4b639e7d81bb2 (patch)
treedccc782fdcb5c2ed199e44036ec7e0e81f8f34de
parentc1331d40912bc808f927c2f742da44530039123e (diff)
Basic mode changes with inputHEADmain
-rw-r--r--HelloWorld/HelloWorld.ino53
1 files changed, 44 insertions, 9 deletions
diff --git a/HelloWorld/HelloWorld.ino b/HelloWorld/HelloWorld.ino
index defcab1..271d576 100644
--- a/HelloWorld/HelloWorld.ino
+++ b/HelloWorld/HelloWorld.ino
@@ -9,23 +9,36 @@ ADXL335 axl;
#define max_size 50
+int mode = 0;
+int next_mode = 0;
+
doubles accelerator_readings[3];
TFT_eSprite spr = TFT_eSprite(&tft);
+void show_splash() {
+ mode = 0;
+ tft.fillScreen(TFT_BLACK);
+ tft.setTextColor(TFT_GREEN);
+ tft.setTextSize(4);
+ tft.drawString("Hello world!", 20, 100);
+}
+
void setup() {
- tft.begin();
- tft.setRotation(3);
- tft.fillScreen(TFT_BLACK);
- tft.setTextColor(TFT_GREEN);
- tft.setTextSize(4);
- tft.drawString("Hello world!", 20, 100);
+ tft.begin();
+ tft.setRotation(3);
+ show_splash();
+
+ spr.createSprite(TFT_HEIGHT, TFT_WIDTH);
- spr.createSprite(TFT_HEIGHT, TFT_WIDTH);
+ pinMode(WIO_KEY_A, INPUT);
+ pinMode(WIO_KEY_B, INPUT);
+ pinMode(WIO_KEY_C, INPUT);
- axl.begin();
+ axl.begin();
}
-void loop() {
+void show_accelerometer_readings() {
+ mode = 1;
spr.fillSprite(TFT_WHITE);
float ax = axl.getAccelerationX();
float ay = axl.getAccelerationY();
@@ -59,5 +72,27 @@ void loop() {
content.draw();
spr.pushSprite(0, 0);
+}
+
+void process_input() {
+ if (digitalRead(WIO_KEY_C) == LOW) {
+ next_mode = 0;
+ }
+ if (digitalRead(WIO_KEY_B) == LOW) {
+ next_mode = 1;
+ }
+ if (digitalRead(WIO_KEY_A) == LOW) {
+ next_mode = 1;
+ }
+}
+
+void loop() {
+ process_input();
+ if (next_mode == 0 && mode != 0) {
+ show_splash();
+ }
+ if (next_mode == 1) {
+ show_accelerometer_readings();
+ }
delay(50);
}