m5atom-dimmable-light's People
m5atom-dimmable-light's Issues
Atom Matrix libraries updated.
I've tweaked the code to update it for the latest Atom Matrix libraries.
#include "M5Atom.h"
int sensorPin = 25; // Define analog pin 25.
// Déclaration des variables.
int couleur = 0;
void setup() {
M5.begin(true, false, true);
Serial.println("");
Serial.println("Initializing M5Stack Atom Matrix");
// M5Stack recommends not setting this value greater than 20
// to avoid melting the screen/cover over the LEDs.
Serial.println("Setting brightness");
LEDS.setBrightness(20);
Serial.println("Finishing setup");
// Initialize device LEDs to on (white), one at a time.
Serial.println("Showing LEDs");
for (uint8_t index = 0; index < 25; index++) {
M5.dis.drawpix(index, CRGB::White);
LEDS.show();
LEDS.delay(50);
}
}
void fillCouleur(CRGB col) {
for (uint8_t index = 0; index < 25; index++) {
M5.dis.drawpix(index, col);
}
}
void loop() {
M5.update();
// Attention : certaines couleur font clignoter le m5atom
// chaque appui change de couleur
if (M5.Btn.wasPressed()) {
Serial.print("Bouton pressé : ");
switch (couleur) {
case 0:
couleur = 1;
fillCouleur(CRGB::Blue);
break;
case 1:
couleur = 2;
fillCouleur(CRGB::Fuchsia);
break;
case 2:
couleur = 3;
fillCouleur(CRGB(0, 255, 0));
break;
case 3:
couleur = 4;
fillCouleur(CRGB(255, 0, 0));
break;
case 4:
couleur = 5;
fillCouleur(CRGB(0, 255, 255));
break;
case 5:
couleur = 0;
fillCouleur(CRGB::White);
break;
}
}
int sensorIn = analogRead(sensorPin);
Serial.println(sensorIn, DEC); // Light intensity.
// High values for bright environment
// Low values for dark environment
/* La valeur brightness à 5 fait que les led sont à fond...
eviter cette valeur ne pas dépasser 50 pour eviter la surchauffe
*/
int brightnessLevel = 0;
if (sensorIn > 3000 && sensorIn < 3500) {
brightnessLevel = 4;
}
else if (sensorIn >= 3500 && sensorIn < 3700) {
brightnessLevel = 10;
}
else if (sensorIn >= 3700 && sensorIn < 4000) {
brightnessLevel = 15;
}
else if (sensorIn >= 4000) {
brightnessLevel = 20;
}
else brightnessLevel = 0;
/*
La valeur de la résistance ne varie pas de façon linéaire mais logarithmique donc la formule
ci dessous n'est pas la meilleure, à utiliser au cas où
brightnessLevel = map(value, 0, 4095, 0, 20) * 1;
ne pas dépasser 20 pour la luminosité du m5atom matrix
et au delà d'un mapping de 0 à 9 sinon les leds ont un comportement étrange
"changement de couleur par exemple"
Using "map" ensures a gradual change between dim and bright LED's over 50 values, not stepped.
brightnessLevel = map(value, min input val, max input val, min output val, max output val);
*/
Serial.println(brightnessLevel);
LEDS.setBrightness(brightnessLevel);
LEDS.delay(500);
}
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.