code comments added, rotary encoder overflow fixed

This commit is contained in:
2025-05-27 16:34:14 +02:00
parent 6ceefa6705
commit 8691bc05eb
2 changed files with 18 additions and 8 deletions

View File

@ -8,7 +8,8 @@
- No need to change checkboxes, only paste the URL and hit OK. - No need to change checkboxes, only paste the URL and hit OK.
4. Install **Raspberry Pi Pico** boards ([HowTo install boards](https://support.arduino.cc/hc/en-us/articles/360016119519-Add-boards-to-Arduino-IDE)) 4. Install **Raspberry Pi Pico** boards ([HowTo install boards](https://support.arduino.cc/hc/en-us/articles/360016119519-Add-boards-to-Arduino-IDE))
5. Install libraries ([HowTo install libraries](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-installing-a-library/)): Adafruit Neopixel, AS5600 (Rob Tillaart), TCA9555 (Rob Tillaart) 5. Install libraries ([HowTo install libraries](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-installing-a-library/)): Adafruit Neopixel, AS5600 (Rob Tillaart), TCA9555 (Rob Tillaart)
6. Choose **Generic RP2350** as board and the correct port 6. Choose **Generic RP2350** as board and the correct port (Mac: /dev/cu.usbmodemXXXX, PC: COMXX Serial Port)
7. Go to **Tools -> Flash Size** and choose **16MB (no FS)** 7. Go to **Tools -> Flash Size** and choose **16MB (no FS)**
8. Hit Upload Button 8. Make your changes in the code
9. Hit Upload Button (Arduino IDE compiles and uploads it automatically)

View File

@ -124,10 +124,12 @@ void loop() {
// Serial.println(ENC.getRevolutions()); // Serial.println(ENC.getRevolutions());
// } // }
// LED Ring leeren
for (int i = 0; i < 48; i++) { for (int i = 0; i < 48; i++) {
ui_pixels.setPixelColor(i + 3, edge_pixels.Color(0, 0, 0)); ui_pixels.setPixelColor(i + 3, edge_pixels.Color(0, 0, 0));
} }
// flag = true when a button is pushed
if (flag) { if (flag) {
int val = TCA.read16(); int val = TCA.read16();
Serial.println(val, BIN); Serial.println(val, BIN);
@ -143,6 +145,7 @@ void loop() {
if (HAPTIC) { if (HAPTIC) {
digitalWrite(6, HIGH); digitalWrite(6, HIGH);
} }
// Make beep
if (AURAL) { if (AURAL) {
digitalWrite(7, HIGH); digitalWrite(7, HIGH);
click = true; click = true;
@ -150,19 +153,21 @@ void loop() {
click = false; click = false;
digitalWrite(7, LOW); digitalWrite(7, LOW);
} }
// Make vibration
if(HAPTIC){ if(HAPTIC){
if(!AURAL) delay(50); if(!AURAL) delay(50);
digitalWrite(6, LOW); digitalWrite(6, LOW);
} }
// Flash led ring
for (int i = 0; i < 48; i++) { for (int i = 0; i < 48; i++) {
ui_pixels.setPixelColor(i + 3, edge_pixels.Color(0, 15, 0)); ui_pixels.setPixelColor(i + 3, edge_pixels.Color(0, 15, 0));
} }
// Switch through LED matrix
if(buttons[RIGHT]) active++; if(buttons[RIGHT]) active++;
if(buttons[LEFT]) active--; if(buttons[LEFT]) active--;
if(active == 13) active = 0; if(active == 13) active = 0;
if(active == -1) active = 12; if(active == -1) active = 12;
} }
// 11111110 11111111 button right
// EDGE LEDs // EDGE LEDs
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
@ -174,18 +179,22 @@ void loop() {
ui_pixels.setPixelColor(1, edge_pixels.Color(0, 0, 15)); ui_pixels.setPixelColor(1, edge_pixels.Color(0, 0, 15));
ui_pixels.setPixelColor(2, edge_pixels.Color(0, 0, 15)); ui_pixels.setPixelColor(2, edge_pixels.Color(0, 0, 15));
// empty LED matrix
for (int i = 0; i < 13; i++) { for (int i = 0; i < 13; i++) {
ui_pixels.setPixelColor(i + 3 + 48 + 4, edge_pixels.Color(0, 0, 0)); ui_pixels.setPixelColor(i + 3 + 48 + 4, edge_pixels.Color(0, 0, 0));
} }
// set active LED matrix LED
ui_pixels.setPixelColor(active + 3 + 48 + 4, edge_pixels.Color(255, 255, 255)); ui_pixels.setPixelColor(active + 3 + 48 + 4, edge_pixels.Color(255, 255, 255));
active_led_ring = abs((position / 256) % 48); if(position < 0) position += 4096;
active_led_ring = (position / 32) % 48;
// set active LED ring LED
ui_pixels.setPixelColor(active_led_ring + 3, edge_pixels.Color(255, 255, 255)); ui_pixels.setPixelColor(active_led_ring + 3, edge_pixels.Color(255, 255, 255));
// put your main code here, to run repeatedly:
edge_pixels.show(); // Set all pixel colors to 'off' edge_pixels.show();
ui_pixels.show(); // Set all pixel colors to 'off' ui_pixels.show();
delay(1); delay(1); // wait 1ms
} }