Skip to content

Commit c88c68c

Browse files
authored
Merge pull request #2401 from ladyada/main
add esp32-sx reverse TFT test and a fancy ws2801-based menorah code
2 parents 88e0aa6 + a2c13bd commit c88c68c

File tree

3 files changed

+204
-0
lines changed

3 files changed

+204
-0
lines changed

Factory_Tests/Feather_ESP32S2_ReverseTFT_FactoryTest/.feather_esp32s2_tft.test.only

Whitespace-only changes.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// SPDX-FileCopyrightText: 2022 Limor Fried for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <Arduino.h>
6+
#include "Adafruit_MAX1704X.h"
7+
#include <Adafruit_NeoPixel.h>
8+
#include "Adafruit_TestBed.h"
9+
#include <Adafruit_BME280.h>
10+
#include <Adafruit_ST7789.h>
11+
#include <Fonts/FreeSans12pt7b.h>
12+
13+
Adafruit_BME280 bme; // I2C
14+
bool bmefound = false;
15+
extern Adafruit_TestBed TB;
16+
17+
Adafruit_MAX17048 lipo;
18+
Adafruit_ST7789 display = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
19+
20+
GFXcanvas16 canvas(240, 135);
21+
22+
void setup() {
23+
Serial.begin(115200);
24+
//while (! Serial) delay(10);
25+
26+
delay(100);
27+
28+
TB.neopixelPin = PIN_NEOPIXEL;
29+
TB.neopixelNum = 1;
30+
TB.begin();
31+
TB.setColor(WHITE);
32+
33+
display.init(135, 240); // Init ST7789 240x135
34+
display.setRotation(3);
35+
canvas.setFont(&FreeSans12pt7b);
36+
canvas.setTextColor(ST77XX_WHITE);
37+
38+
if (!lipo.begin()) {
39+
Serial.println(F("Couldnt find Adafruit MAX17048?\nMake sure a battery is plugged in!"));
40+
while (1) delay(10);
41+
}
42+
43+
Serial.print(F("Found MAX17048"));
44+
Serial.print(F(" with Chip ID: 0x"));
45+
Serial.println(lipo.getChipID(), HEX);
46+
47+
if (TB.scanI2CBus(0x77)) {
48+
Serial.println("BME280 address");
49+
50+
unsigned status = bme.begin();
51+
if (!status) {
52+
Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
53+
Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
54+
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
55+
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
56+
Serial.print(" ID of 0x60 represents a BME 280.\n");
57+
Serial.print(" ID of 0x61 represents a BME 680.\n");
58+
return;
59+
}
60+
Serial.println("BME280 found OK");
61+
bmefound = true;
62+
}
63+
64+
pinMode(0, INPUT_PULLUP);
65+
pinMode(1, INPUT_PULLDOWN);
66+
pinMode(2, INPUT_PULLDOWN);
67+
}
68+
69+
uint8_t j = 0;
70+
71+
void loop() {
72+
Serial.println("**********************");
73+
74+
TB.printI2CBusScan();
75+
76+
if (j % 2 == 0) {
77+
canvas.fillScreen(ST77XX_BLACK);
78+
canvas.setCursor(0, 17);
79+
canvas.setTextColor(ST77XX_RED);
80+
canvas.println("Adafruit Feather");
81+
canvas.setTextColor(ST77XX_YELLOW);
82+
canvas.println("ESP32-S2 TFT Demo");
83+
canvas.setTextColor(ST77XX_GREEN);
84+
canvas.print("Battery: ");
85+
canvas.setTextColor(ST77XX_WHITE);
86+
canvas.print(lipo.cellVoltage(), 1);
87+
canvas.print(" V / ");
88+
canvas.print(lipo.cellPercent(), 0);
89+
canvas.println("%");
90+
canvas.setTextColor(ST77XX_BLUE);
91+
canvas.print("I2C: ");
92+
canvas.setTextColor(ST77XX_WHITE);
93+
for (uint8_t a=0x01; a<=0x7F; a++) {
94+
if (TB.scanI2CBus(a, 0)) {
95+
canvas.print("0x");
96+
canvas.print(a, HEX);
97+
canvas.print(", ");
98+
}
99+
}
100+
canvas.println("");
101+
canvas.print("Buttons: ");
102+
Serial.println(digitalRead(0));
103+
Serial.println(digitalRead(1));
104+
Serial.println(digitalRead(2));
105+
if (!digitalRead(0)) {
106+
canvas.print("D0, ");
107+
}
108+
if (digitalRead(1)) {
109+
canvas.print("D1, ");
110+
}
111+
if (digitalRead(2)) {
112+
canvas.print("D2, ");
113+
}
114+
display.drawRGBBitmap(0, 0, canvas.getBuffer(), 240, 135);
115+
pinMode(TFT_BACKLITE, OUTPUT);
116+
digitalWrite(TFT_BACKLITE, HIGH);
117+
}
118+
119+
TB.setColor(TB.Wheel(j++));
120+
delay(10);
121+
return;
122+
}

WS2801_LED_Menorah/code.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# SPDX-FileCopyrightText: 2021 Liz Clark for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
"""Jack-o'-Lantern flame example Adafruit Circuit Playground Express"""
5+
import time
6+
import math
7+
import random
8+
import board
9+
import adafruit_ws2801
10+
from digitalio import DigitalInOut, Direction, Pull
11+
12+
# button setup
13+
button = DigitalInOut(board.A2)
14+
button.direction = Direction.INPUT
15+
button.pull = Pull.UP
16+
17+
# pixel setup
18+
pixel_num = 9
19+
pixel_offset = 2
20+
pixels = adafruit_ws2801.WS2801(board.SDA1, board.SCL1, pixel_num+pixel_offset, brightness=1, auto_write=False)
21+
22+
pixel_prev = [128] * len(pixels)
23+
24+
lit_candles = None
25+
night = 0
26+
timestamp = None
27+
28+
def split(first, second, offset):
29+
"""
30+
Subdivide a brightness range, introducing a random offset in middle,
31+
then call recursively with smaller offsets along the way.
32+
@param1 first: Initial brightness value.
33+
@param1 second: Ending brightness value.
34+
@param1 offset: Midpoint offset range is +/- this amount max.
35+
"""
36+
if offset != 0:
37+
mid = ((first + second + 1) / 2 + random.randint(-offset, offset))
38+
offset = int(offset / 2)
39+
split(first, mid, offset)
40+
split(mid, second, offset)
41+
else:
42+
level = math.pow(first / 255.0, 2.7) * 255.0 + 0.5
43+
return level
44+
45+
while True:
46+
if not button.value:
47+
while not button.value:
48+
time.sleep(0.01) # debounce
49+
night += 1 # next night
50+
if night == 9: # wrap around
51+
night = 0 # shamash-only mode
52+
lit_candles = None # reset the lights
53+
if not lit_candles:
54+
print("Current night: ", night)
55+
night_countup = 0
56+
timestamp = time.monotonic()-1
57+
58+
if night == 0:
59+
# special case of shamash-only
60+
lit_candles = [False, False, False, False, True, False, False, False, False]
61+
elif (night_countup != night) and (time.monotonic() - timestamp >= 1):
62+
# we slowly 'light' up the candles from left to right, once a second
63+
night_countup += 1
64+
lit_candles = [False] * (8-night) + [True] * night_countup + [False] * (night-night_countup)
65+
lit_candles.insert(4, True) # shamash always on
66+
print("Count up candle #", night_countup, lit_candles)
67+
timestamp = time.monotonic()
68+
69+
# animate candles
70+
for p in range(len(pixels)-pixel_offset):
71+
if not lit_candles[p]:
72+
pixels[p+pixel_offset] = 0
73+
continue
74+
if p == 4:
75+
level = random.randint(128, 255)
76+
else:
77+
level = random.randint(64, 191)
78+
79+
color = split(pixel_prev[p], level, 32)
80+
pixels[p+pixel_offset] = ((int(level), int(level / 8), int(level / 48)))
81+
pixel_prev[p] = level
82+
pixels.show()

0 commit comments

Comments
 (0)