Skip to content

Commit 70e50a7

Browse files
authored
Merge branch 'master' into cpb-cpx-cap-touch-update
2 parents e71ecb5 + 90f5e76 commit 70e50a7

7 files changed

Lines changed: 198 additions & 18 deletions

File tree

M4_Eyes/M4_Eyes.ino

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,12 @@ void setup() {
162162
delay(20);
163163
#endif
164164

165-
uint8_t e;
165+
uint8_t e, rtna = 0x01; // Screen refresh rate control (datasheet 9.2.18, FRCTRL2)
166166
// Initialize displays
167167
for(e=0; e<NUM_EYES; e++) {
168168
eye[e].display = new Adafruit_ST7789(eye[e].spi, eye[e].cs, eye[e].dc, eye[e].rst);
169169
eye[e].display->init(240, 240);
170+
eye[e].display->sendCommand(0xC6, &rtna, 1);
170171
eye[e].spi->setClockSource(DISPLAY_CLKSRC);
171172
eye[e].display->fillScreen(0x1234);
172173
eye[e].display->setRotation(0);
@@ -510,24 +511,30 @@ void loop() {
510511
timeToNextBlink = blinkDuration * 3 + random(4000000);
511512
}
512513

513-
// Eyelids naturally "track" the pupils (move up or down automatically)
514-
int ix = (int)map2screen(mapRadius - eye[eyeNum].eyeX) + 120, // Pupil position
515-
iy = (int)map2screen(mapRadius - eye[eyeNum].eyeY) + 120; // on screen
516-
iy += irisRadius / 2; // top edge of iris (ish) in screen pixels
517514
float uq, lq; // So many sloppy temp vars in here for now, sorry
518-
if(eyeNum & 1) ix = 239 - ix; // Flip for right eye
519-
if(iy > upperOpen[ix]) {
520-
uq = 1.0;
521-
} else if(iy < upperClosed[ix]) {
522-
uq = 0.0;
523-
} else {
524-
uq = (float)(iy - upperClosed[ix]) / (float)(upperOpen[ix] - upperClosed[ix]);
525-
}
526-
if(booped) {
527-
uq = 0.9;
528-
lq = 0.7;
515+
if(tracking) {
516+
// Eyelids naturally "track" the pupils (move up or down automatically)
517+
int ix = (int)map2screen(mapRadius - eye[eyeNum].eyeX) + 120, // Pupil position
518+
iy = (int)map2screen(mapRadius - eye[eyeNum].eyeY) + 120; // on screen
519+
iy += irisRadius * trackFactor;
520+
if(eyeNum & 1) ix = 239 - ix; // Flip for right eye
521+
if(iy > upperOpen[ix]) {
522+
uq = 1.0;
523+
} else if(iy < upperClosed[ix]) {
524+
uq = 0.0;
525+
} else {
526+
uq = (float)(iy - upperClosed[ix]) / (float)(upperOpen[ix] - upperClosed[ix]);
527+
}
528+
if(booped) {
529+
uq = 0.9;
530+
lq = 0.7;
531+
} else {
532+
lq = 1.0 - uq;
533+
}
529534
} else {
530-
lq = 1.0 - uq;
535+
// If no tracking, eye is FULLY OPEN when not blinking
536+
uq = 1.0;
537+
lq = 1.0;
531538
}
532539
// Dampen eyelid movements slightly
533540
// SAVE upper & lower lid factors per eye,

M4_Eyes/file.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,15 @@ void loadConfig(char *filename) {
266266
JsonVariant iristv = doc["irisTexture"],
267267
scleratv = doc["scleraTexture"];
268268

269+
v = doc["tracking"];
270+
if(v.is<bool>()) tracking = v.as<bool>();
271+
v = doc["squint"];
272+
if(v.is<float>()) {
273+
trackFactor = 1.0 - v.as<float>();
274+
if(trackFactor < 0.0) trackFactor = 0.0;
275+
else if(trackFactor > 1.0) trackFactor = 1.0;
276+
}
277+
269278
// Convert clockwise int (0-1023) or float (0.0-1.0) values to CCW int used internally:
270279
v = doc["irisSpin"];
271280
if(v.is<float>()) irisSpin = v.as<float>() * -1024.0;

M4_Eyes/globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ GLOBAL_VAR uint16_t lightSensorMax GLOBAL_INIT(1023);
6969
GLOBAL_VAR float lightSensorCurve GLOBAL_INIT(1.0);
7070
GLOBAL_VAR float irisMin GLOBAL_INIT(0.45);
7171
GLOBAL_VAR float irisRange GLOBAL_INIT(0.35);
72+
GLOBAL_VAR bool tracking GLOBAL_INIT(true);
73+
GLOBAL_VAR float trackFactor GLOBAL_INIT(0.5);
7274

7375
// Pin definition stuff will go here
7476

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import time
2+
import board
3+
import busio
4+
from adafruit_ht16k33 import segments
5+
6+
# Create the I2C interface.
7+
i2c = busio.I2C(board.SCL, board.SDA)
8+
9+
# Create the LED segment class.
10+
# This creates a 14 segment 4 character display:
11+
display = segments.Seg14x4(i2c)
12+
13+
# Clear the display.
14+
display.fill(0)
15+
16+
# set brightness, range 1-15, 15 max brightness
17+
display.brightness = 15
18+
19+
# show phrase on alphanumeric display
20+
message = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"
21+
count = 0
22+
23+
# print one character at time with short sleep
24+
# creates smooth scrolling effect
25+
while count < len(message):
26+
display.print(message[count])
27+
count += 1
28+
time.sleep(0.3)
29+
30+
# Can just print a number
31+
display.print(42)
32+
time.sleep(1)
33+
34+
# Set the first character to '1':
35+
display[0] = '1'
36+
# Set the second character to '2':
37+
display[1] = '2'
38+
# Set the third character to 'A':
39+
display[2] = 'A'
40+
# Set the forth character to 'B':
41+
display[3] = 'B'
42+
time.sleep(1)
43+
44+
numbers = [0.0, 1.0, -1.0, 0.55, -0.55, 10.23, -10.2, 100.5, -100.5]
45+
46+
# print negative and positive floating point numbers
47+
for i in numbers:
48+
display.print(i)
49+
time.sleep(0.5)
50+
51+
# print hex values, enable colon
52+
for i in range(0xFF):
53+
display.fill(0)
54+
display.print(':')
55+
display.print(hex(i))
56+
time.sleep(0.25)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Basic example of using the Bi-color 24 segment bargraph display.
2+
# This example and library is meant to work with Adafruit CircuitPython API.
3+
# Author: Carter Nelson
4+
# License: Public Domain
5+
6+
import time
7+
import board
8+
import busio
9+
10+
# Import the Bicolor24 driver from the HT16K33 module
11+
from adafruit_ht16k33.bargraph import Bicolor24
12+
13+
# Create the I2C interface
14+
i2c = busio.I2C(board.SCL, board.SDA)
15+
16+
# Create the LED bargraph class.
17+
bc24 = Bicolor24(i2c)
18+
19+
# Set individual segments of bargraph
20+
bc24[0] = bc24.LED_RED
21+
bc24[1] = bc24.LED_GREEN
22+
bc24[2] = bc24.LED_YELLOW
23+
24+
time.sleep(2)
25+
26+
# Turn them all off
27+
bc24.fill(bc24.LED_OFF)
28+
29+
# Turn them on in a loop
30+
for i in range(24):
31+
bc24[i] = bc24.LED_RED
32+
time.sleep(0.1)
33+
bc24[i] = bc24.LED_OFF
34+
35+
time.sleep(1)
36+
37+
# Fill the entrire bargraph
38+
bc24.fill(bc24.LED_GREEN)

Matrix_7-Segment_LED_Backpack_Raspberry_Pi/matrix8x8_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
# illuminate a column one LED at a time
2525
while col < col_max:
26-
matrix[row, col] = 1
26+
matrix[row, col] = 2
2727
col += 1
2828
time.sleep(.2)
2929

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Import all pins
2+
import time
3+
import board
4+
import busio
5+
from adafruit_ht16k33 import matrix
6+
7+
# Create the I2C interface
8+
i2c = busio.I2C(board.SCL, board.SDA)
9+
10+
# Create the LED bargraph class.
11+
bicolor = matrix.Matrix8x8x2(i2c)
12+
13+
# color mapping shortcut
14+
OFF = 0
15+
GREEN = 1
16+
RED = 2
17+
YELLOW = 3
18+
19+
# Set individual segments of the bicolor matrix
20+
# Illuminate the first three pixels
21+
bicolor[0,0] = GREEN
22+
bicolor[0,1] = RED
23+
bicolor[0,2] = YELLOW
24+
25+
time.sleep(2)
26+
27+
# Edges of an 8x8 matrix
28+
col_max = 8
29+
row_max = 8
30+
31+
# Turn all pixels off
32+
bicolor.fill(OFF)
33+
col = 0
34+
row = 0
35+
36+
# Illuminate each pixel with each color
37+
while row < row_max:
38+
39+
# Turn them on in a loop
40+
while col < col_max:
41+
bicolor[row, col] = RED
42+
time.sleep(.25)
43+
bicolor[row, col] = GREEN
44+
time.sleep(.25)
45+
bicolor[row, col] = YELLOW
46+
time.sleep(.25)
47+
col += 1
48+
49+
# next row when previous column is full
50+
if row < row_max:
51+
row += 1
52+
col = 0
53+
54+
# clear matrix, start over
55+
else:
56+
row = col = 0
57+
bicolor.fill(OFF)
58+
59+
time.sleep(1)
60+
61+
# Fill the entrire display, with each color
62+
bicolor.fill(GREEN)
63+
time.sleep(1)
64+
bicolor.fill(RED)
65+
time.sleep(1)
66+
bicolor.fill(YELLOW)
67+
time.sleep(1)
68+
bicolor.fill(OFF)

0 commit comments

Comments
 (0)