https://beta.openai.com/playground/p/HK ... avinci-003
When I try and verify the sketch, things get caught up on the "<Adafruit_QTpy.h>" portion.
I've tried searching high and low for where to get this library... can someone point me in the right direction?
- Or maybe the sketch needs to be adjusted?
---------------------------------------------------------------------------------------------------------------------
Code: Select all
/*
This is an Arduino IDE sketch, which will run on the "Adafruit QT Py ESP32-C3 WiFi Dev Board"
Input is collected from a "NeoKey 1x4 QT I2C - Four Mechanical Key Switches with NeoPixels - STEMMA QT / Qwiic" connected to the "Adafruit QT Py ESP32-C3 WiFi Dev Board" through a STEMMA QT cable.
General Idea:
- Push a button on the NeoKey, and the QT Py connects to the internet and inserts a new record at the bottom of a Google Sheet - recording the key press.
Configurable Parameters Include:
1) Google Sheets API key to use
2) Google Sheet URL to connect to
3) Google Sheet tab-name to insert a row into
4) The individual values to use for each of the 4 NeoKeys
5) The WiFi SSID to connect to
6) The Password for the WiFi
Details that need to be recorded into the Google Sheet Row:
1) Timestamp of the event
2) The value from the key pressed
3) a GUID
Explanation of the main loop:
Start watching the NeoKeys for changes, querying them only once a second
If a key is pressed, turn the key's LED Yellow (as long as it's held - up to 2 seconds); if they key is held for less than 2 seconds and released, turn the LED off
If the key is held for longer than 2 seconds: begin a record creation process
First begin connecting to wifi; while attempting to connect, flash the led of the key that was pressed blue every half second. Once successfully connected to wifi, stop blinking the LED and turn it solid blue
Next insert the google sheet row at the bottom of the sheet specified using the Google Sheets API
If the record is successfully created, turn the LED green for 5 seconds and then turn it off.
If the record is NOT created, turn the LED red for 5 seconds and then turn it off.
*/
// Include the necessary libraries
#include <Arduino.h>
#include <Wire.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <Adafruit_QTpy.h>
#include <Adafruit_NeoKey.h>
// Create a QTpy object
Adafruit_QTpy qtpy;
// Create a NeoKey object
Adafruit_NeoKey neokey;
// Configure the WiFi connection
const char* ssid = "MY_SSID";
const char* password = "MY_PASSWORD";
// Configure the Google Sheets API connection
const char* apiKey = "MY_API_KEY";
const char* sheetUrl = "MY_SHEET_URL";
const char* sheetName = "MY_SHEET_NAME";
// Configure the NeoKeys
int key1Value = 1;
int key2Value = 2;
int key3Value = 3;
int key4Value = 4;
void setup() {
Serial.begin(115200);
// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// Initialize the QTpy and NeoKey
if(!qtpy.begin(Wire)){
Serial.println("Failed to initialize QTpy!");
while(1);
}
if(!neokey.begin(&qtpy)){
Serial.println("Failed to initialize NeoKey!");
while(1);
}
Serial.println("QTpy and NeoKey initialized");
}
void loop() {
// Check for key presses
int keyPressed = neokey.readSwitch();
if (keyPressed > 0) {
Serial.println("Key pressed: " + String(keyPressed));
int keyValue = 0;
switch (keyPressed) {
case 1:
keyValue = key1Value;
break;
case 2:
keyValue = key2Value;
break;
case 3:
keyValue = key3Value;
break;
case 4:
keyValue = key4Value;
break;
default:
break;
}
if (keyValue > 0) {
// Turn on the LED of the key that was pressed
neokey.setPixelColor(keyPressed - 1, Adafruit_NeoPixel::Color(255, 255, 0));
neokey.show();
delay(2000);
// Connect to WiFi
Serial.println("Connecting to WiFi...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
neokey.setPixelColor(keyPressed - 1, Adafruit_NeoPixel::Color(0, 0, 255));
neokey.show();
delay(500);
neokey.setPixelColor(keyPressed - 1, Adafruit_NeoPixel::Color(0, 0, 0));
neokey.show();
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// Turn on the LED of the key that was pressed
neokey.setPixelColor(keyPressed - 1, Adafruit_NeoPixel::Color(0, 0, 255));
neokey.show();
delay(500);
// Create the HTTP request
HTTPClient http;
http.begin(sheetUrl);
http.addHeader("Content-Type", "application/json");
http.addHeader("Authorization", "Bearer " + String(apiKey));
int httpCode = http.POST("{\"values\": [[\"" + String(millis()) + "\", \"" + String(keyValue) + "\", \"GUID\"]]}");
http.end();
Serial.println("Request sent, response code: " + String(httpCode));
// Turn on the LED of the key that was pressed
if (httpCode == 200) {
neokey.setPixelColor(keyPressed - 1, Adafruit_NeoPixel::Color(0, 255, 0));
neokey.show();
delay(5000);
} else {
neokey.setPixelColor(keyPressed - 1, Adafruit_NeoPixel::Color(255, 0, 0));
neokey.show();
delay(5000);
}
// Turn off the LED of the key that was pressed
neokey.setPixelColor(keyPressed - 1, Adafruit_NeoPixel::Color(0, 0, 0));
neokey.show();
}
}
delay(1000);
}