first commit

This commit is contained in:
Jérôme Delacotte
2025-03-06 11:15:32 +01:00
commit 7b30d6e298
5276 changed files with 2108927 additions and 0 deletions

View File

@@ -0,0 +1,230 @@
// Adafruit IO Time Tracking Cube
// Tutorial Link: https://learn.adafruit.com/time-tracking-cube
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Brent Rubell for Adafruit Industries
// Copyright (c) 2019 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.
/************************** Configuration ***********************************/
// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"
/************************ Example Starts Here *******************************/
#include <Wire.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_NeoPixel.h>
// Prop-Maker Wing
#define NEOPIXEL_PIN 2
#define POWER_PIN 15
// Used for Pizeo
#define PIEZO_PIN 0
// # of Pixels Attached
#define NUM_PIXELS 8
// Adafruit_LIS3DH Setup
Adafruit_LIS3DH lis = Adafruit_LIS3DH();
// NeoPixel Setup
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
// Set up the 'cubeTask' feed
AdafruitIO_Feed *cubetask = io.feed("cubetask");
/* Time Tracking Cube States
* 1: Cube Tilted Left
* 2: Cube Tilted Right
* 3: Cube Neutral, Top
*/
int cubeState = 0;
// Previous cube orientation state
int prvCubeState = 0;
// Tasks (change these to what you're currently working on)
String taskOne = "Write Learn Guide";
String taskTwo = "Write Code";
// Adafruit IO sending delay, in seconds
int sendDelay = 0.5;
// Time-Keeping
unsigned long currentTime;
unsigned long prevTime;
int seconds = 0;
int minutes = 0;
void setup()
{
// start the serial connection
Serial.begin(9600);
// wait for serial monitor to open
while (!Serial)
;
Serial.println("Adafruit IO Time Tracking Cube");
// disabling low-power mode on the prop-maker wing
pinMode(POWER_PIN, OUTPUT);
digitalWrite(POWER_PIN, HIGH);
// Initialize LIS3DH
if (!lis.begin(0x18))
{
Serial.println("Couldnt start");
while (1)
;
}
Serial.println("LIS3DH found!");
lis.setRange(LIS3DH_RANGE_4_G);
// Initialize NeoPixel Strip
strip.begin();
Serial.println("Pixels init'd");
// connect to io.adafruit.com
Serial.print("Connecting to Adafruit IO");
io.connect();
// wait for a connection
while (io.status() < AIO_CONNECTED)
{
Serial.print(".");
delay(500);
}
// we are connected
Serial.println();
Serial.println(io.statusText());
}
void updateTime()
{
// grab the current time from millis()
currentTime = millis() / 1000;
seconds = currentTime - prevTime;
// increase mins.
if (seconds == 60)
{
prevTime = currentTime;
minutes++;
}
}
void updatePixels(uint8_t red, uint8_t green, uint8_t blue)
{
for (int p = 0; p < NUM_PIXELS; p++)
{
strip.setPixelColor(p, red, green, blue);
}
strip.show();
}
void loop()
{
// io.run(); is required for all sketches.
// it should always be present at the top of your loop
// function. it keeps the client connected to
// io.adafruit.com, and processes any incoming data.
io.run();
// Update the timer
updateTime();
// Get a normalized sensor reading
sensors_event_t event;
lis.getEvent(&event);
// Detect cube face orientation
if (event.acceleration.x > 9 && event.acceleration.x < 10)
{
//Serial.println("Cube TILTED: Left");
cubeState = 1;
}
else if (event.acceleration.x < -9)
{
//Serial.println("Cube TILTED: Right");
cubeState = 2;
}
else if (event.acceleration.y < 0 && event.acceleration.y > -1)
{
cubeState = 3;
}
else
{ // orientation not specified
//Serial.println("Cube Idle...");
}
// return if the orientation hasn't changed
if (cubeState == prvCubeState)
return;
// Send to Adafruit IO based off of the orientation of the cube
switch (cubeState)
{
case 1:
Serial.println("Switching to Task 1");
// update the neopixel strip
updatePixels(50, 0, 0);
// play a sound
#if defined(ARDUINO_ARCH_ESP32)
ledcWriteTone(PIEZO_PIN, 650);
#else
tone(PIEZO_PIN, 650, 300);
#endif
Serial.print("Sending to Adafruit IO -> ");
Serial.println(taskTwo);
cubetask->save(taskTwo, minutes);
// reset the timer
minutes = 0;
break;
case 2:
Serial.println("Switching to Task 2");
// update the neopixel strip
updatePixels(0, 50, 0);
// play a sound
#if defined(ARDUINO_ARCH_ESP32)
ledcWriteTone(PIEZO_PIN, 850);
#else
tone(PIEZO_PIN, 850, 300);
#endif
Serial.print("Sending to Adafruit IO -> ");
Serial.println(taskOne);
cubetask->save(taskOne, minutes);
// reset the timer
minutes = 0;
break;
case 3:
updatePixels(0, 0, 50);
// play a sound
#if defined(ARDUINO_ARCH_ESP32)
ledcWriteTone(PIEZO_PIN, 950);
#else
tone(PIEZO_PIN, 950, 300);
#endif
break;
}
// save cube state
prvCubeState = cubeState;
// Delay the send to Adafruit IO
delay(sendDelay * 1000);
}

View File

@@ -0,0 +1,72 @@
/************************ Adafruit IO Config *******************************/
// visit io.adafruit.com if you need to create an account,
// or if you need your Adafruit IO key.
#define IO_USERNAME "your_username"
#define IO_KEY "your_key"
/******************************* WIFI **************************************/
// the AdafruitIO_WiFi client will work with the following boards:
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
// - Feather WICED -> https://www.adafruit.com/products/3056
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
// - Adafruit Metro M4 Express AirLift Lite ->
// https://www.adafruit.com/product/4000
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
#define WIFI_SSID "your_ssid"
#define WIFI_PASS "your_pass"
// uncomment the following line if you are using airlift
// #define USE_AIRLIFT
// uncomment the following line if you are using winc1500
// #define USE_WINC1500
// uncomment the following line if you are using mrk1010 or nano 33 iot
//#define ARDUINO_SAMD_MKR1010
// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
defined(ADAFRUIT_PYPORTAL)
// Configure the pins used for the ESP32 connection
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
// Don't change the names of these #define's! they match the variant ones
#define SPIWIFI SPI
#define SPIWIFI_SS 10 // Chip select pin
#define NINA_ACK 9 // a.k.a BUSY or READY pin
#define NINA_RESETN 6 // Reset pin
#define NINA_GPIO0 -1 // Not connected
#endif
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
#else
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
#endif
/******************************* FONA **************************************/
// the AdafruitIO_FONA client will work with the following boards:
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
// uncomment the following two lines for 32u4 FONA,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_FONA.h"
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
/**************************** ETHERNET ************************************/
// the AdafruitIO_Ethernet client will work with the following boards:
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
// uncomment the following two lines for ethernet,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_Ethernet.h"
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);