|
| 1 | +// SPDX-FileCopyrightText: 2023 Limor Fried for Adafruit Industries |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +#include <Adafruit_LIS3DH.h> |
| 6 | +#include <Adafruit_TestBed.h> |
| 7 | +#include <WiFi.h> |
| 8 | +#include <WiFiAP.h> |
| 9 | +#include <Adafruit_Protomatter.h> |
| 10 | + |
| 11 | + |
| 12 | +extern Adafruit_TestBed TB; |
| 13 | +Adafruit_LIS3DH lis = Adafruit_LIS3DH(); |
| 14 | + |
| 15 | +uint8_t mcp1_matrix_pins[8] = {45, 21, 37, 39, 38, 40, 41, 42}; // A, E, B2, G2, R2, B1, G1, R1 |
| 16 | +uint8_t mcp2_matrix_pins[8] = {12, 14, 47, 2, 255, 35, 48, 36}; // A0, OE, LAT, CLK, NC, D, C, B |
| 17 | +#define LIGHT_SENSOR 5 |
| 18 | + |
| 19 | +int32_t total_time; |
| 20 | + |
| 21 | +bool matrixpinsOK = false, accelOK = false, gpioOK = false, jstOK = false, wifiOK = false, testMode = false, lightOK = false; |
| 22 | +uint8_t j=0; |
| 23 | + |
| 24 | +uint8_t rgbPins[] = {42, 41, 40, 38, 39, 37}; |
| 25 | +uint8_t addrPins[] = {45, 36, 48, 35, 21}; |
| 26 | +uint8_t clockPin = 2; |
| 27 | +uint8_t latchPin = 47; |
| 28 | +uint8_t oePin = 14; |
| 29 | +Adafruit_Protomatter matrix( |
| 30 | + 64, // Width of matrix (or matrix chain) in pixels |
| 31 | + 4, // Bit depth, 1-6 |
| 32 | + 1, rgbPins, // # of matrix chains, array of 6 RGB pins for each |
| 33 | + 4, addrPins, // # of address pins (height is inferred), array of pins |
| 34 | + clockPin, latchPin, oePin, // Other matrix control pins |
| 35 | + false); // No double-buffering here (see "doublebuffer" example) |
| 36 | + |
| 37 | + |
| 38 | +void setup() { |
| 39 | + Serial.begin(115200); |
| 40 | + //while (!Serial) delay(10); |
| 41 | + |
| 42 | + TB.ledPin = LED_BUILTIN; |
| 43 | + TB.neopixelPin = PIN_NEOPIXEL; |
| 44 | + TB.neopixelNum = 1; |
| 45 | + TB.begin(); |
| 46 | + |
| 47 | + total_time = millis(); |
| 48 | + |
| 49 | + WiFi.softAPIP(); |
| 50 | + WiFi.softAP("Matrix Portal ESP32-S3", "adafruit"); |
| 51 | + |
| 52 | + if (! testMode) { |
| 53 | + // Initialize matrix... |
| 54 | + ProtomatterStatus status = matrix.begin(); |
| 55 | + Serial.print("Protomatter begin() status: "); |
| 56 | + Serial.println((int)status); |
| 57 | + if(status != PROTOMATTER_OK) { |
| 58 | + // DO NOT CONTINUE if matrix setup encountered an error. |
| 59 | + for(;;); |
| 60 | + } |
| 61 | + // Make four color bars (red, green, blue, white) with brightness ramp: |
| 62 | + for(int x=0; x<matrix.width(); x++) { |
| 63 | + uint8_t level = x * 256 / matrix.width(); // 0-255 brightness |
| 64 | + matrix.drawPixel(x, matrix.height() - 4, matrix.color565(level, 0, 0)); |
| 65 | + matrix.drawPixel(x, matrix.height() - 3, matrix.color565(0, level, 0)); |
| 66 | + matrix.drawPixel(x, matrix.height() - 2, matrix.color565(0, 0, level)); |
| 67 | + matrix.drawPixel(x, matrix.height() - 1, |
| 68 | + matrix.color565(level, level, level)); |
| 69 | + } |
| 70 | + // You'll notice the ramp looks smoother as bit depth increases |
| 71 | + // (second argument to the matrix constructor call above setup()). |
| 72 | + |
| 73 | + // Simple shapes and text, showing GFX library calls: |
| 74 | + matrix.drawCircle(12, 10, 9, matrix.color565(255, 0, 0)); |
| 75 | + matrix.drawRect(14, 6, 17, 17, matrix.color565(0, 255, 0)); |
| 76 | + matrix.drawTriangle(32, 9, 41, 27, 23, 27, matrix.color565(0, 0, 255)); |
| 77 | + matrix.println("ADAFRUIT"); // Default text color is white |
| 78 | + if (matrix.height() > 32) { |
| 79 | + matrix.setCursor(0, 32); |
| 80 | + matrix.println("64 pixel"); // Default text color is white |
| 81 | + matrix.println("matrix"); // Default text color is white |
| 82 | + } |
| 83 | + |
| 84 | + // AFTER DRAWING, A show() CALL IS REQUIRED TO UPDATE THE MATRIX! |
| 85 | + |
| 86 | + matrix.show(); // Copy data to matrix buffers |
| 87 | + } |
| 88 | + pinMode(LIGHT_SENSOR, INPUT); |
| 89 | +} |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | +void loop() { |
| 94 | + if (!testMode) { |
| 95 | + if (j == 64) { |
| 96 | + TB.printI2CBusScan(); |
| 97 | + } |
| 98 | + |
| 99 | + if (j == 255) { |
| 100 | + TB.setColor(WHITE); |
| 101 | + pinMode(13, OUTPUT); |
| 102 | + digitalWrite(13, HIGH); |
| 103 | + Serial.println("scan start"); |
| 104 | + // WiFi.scanNetworks will return the number of networks found |
| 105 | + int n = WiFi.scanNetworks(); |
| 106 | + Serial.println("scan done"); |
| 107 | + if (n == 0) { |
| 108 | + Serial.println("no networks found"); |
| 109 | + } else { |
| 110 | + Serial.print(n); |
| 111 | + Serial.println(" networks found"); |
| 112 | + for (int i = 0; i < n; ++i) { |
| 113 | + // Print SSID and RSSI for each network found |
| 114 | + Serial.print(i + 1); |
| 115 | + Serial.print(": "); |
| 116 | + Serial.print(WiFi.SSID(i)); |
| 117 | + Serial.print(" ("); |
| 118 | + Serial.print(WiFi.RSSI(i)); |
| 119 | + Serial.print(")"); |
| 120 | + Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*"); |
| 121 | + delay(10); |
| 122 | + } |
| 123 | + } |
| 124 | + Serial.println(""); |
| 125 | + digitalWrite(13, LOW); |
| 126 | + } |
| 127 | + |
| 128 | + TB.setColor(TB.Wheel(j++)); |
| 129 | + delay(10); |
| 130 | + return; |
| 131 | + } |
| 132 | + delay(100); |
| 133 | + |
| 134 | +} |
0 commit comments