cubelumiere
Table des matières
Cube lumineux
Plans pour découpe laser
Câblage
Code Source
- CubeLumiere.ino
/* INCLUDES *******************************************************************/ #include <Adafruit_NeoPixel.h> #include "OneButton.h" /* CONSTANTES *****************************************************************/ // Used pins of ARDUINO #define PIN_PIXEL 4 // NeoPixel #define PIN_BUTTON_PWR 7 // Power button #define PIN_BUTTON_CHG 8 // Color change button // How many NeoPixels in the strip #define NUMPIXELS 60 // max Hue #define MAXHUE 65535 // Max Hue value #define STEP 9 // Increment #define BRIGHTNESS 60 // Explication needed ? /* VARIABLES ******************************************************************/ int powerOn = 0; // LEDs are on or off uint32_t hueColor = 0; // Current displayed color int colorChange = 0; // The color is changing // Initialise the buttons, with a default low OneButton buttonPower(PIN_BUTTON_PWR, false); OneButton buttonChange(PIN_BUTTON_CHG, false); // Initialise the pixel ring Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN_PIXEL, NEO_GRB + NEO_KHZ800); void setup() { // Make the button pin an input pinMode( PIN_BUTTON_PWR, INPUT ); pinMode( PIN_BUTTON_CHG, INPUT ); // Attatch click functions to the buttons buttonPower.attachClick(setPower); buttonChange.attachClick(changeColor); // Initialise the strip and set it's brightness to 100% pixels.begin(); pixels.setBrightness(BRIGHTNESS); }; void loop() { // Every cycle we need to tick the button state buttonPower.tick(); buttonChange.tick(); if (powerOn == 0) { // If swiched off, set all pixels to black for (int i=0; i<NUMPIXELS; i++) { pixels.setPixelColor(i, pixels.Color(0,0,0)); }; } else { // If we are choosing a color, change the color if (colorChange == 1) { hueColor = hueColor + STEP; if (hueColor > MAXHUE) { hueColor = 0; }; // Little delay after each change delay(2); }; // Set all pixels with the new color for(int i=0; i<pixels.numPixels(); i++) { // For each pixel in strip... pixels.setPixelColor(i, pixels.ColorHSV(hueColor, 255, 255)); }; }; // Apply changes to the pixels pixels.show(); }; void setPower() { if (powerOn == 0) { powerOn = 1; // When switch off, stop changing color colorChange = 0; } else { powerOn = 0; }; }; void changeColor() { if (colorChange == 0) { colorChange = 1; } else { colorChange = 0; }; };
cubelumiere.txt · Dernière modification : 2023/07/30 15:19 de faber