Ver código fonte

upgrade neopixel

Francois PONSARD 2 anos atrás
pai
commit
efaa8e6a8d
3 arquivos alterados com 197 adições e 196 exclusões
  1. 57 57
      README.md
  2. 126 125
      code/veilleuse/veilleuse.ino
  3. 14 14
      stl/README.md

+ 57 - 57
README.md

@@ -1,57 +1,57 @@
-> **STATUS** : 20201025 : Ca marche plutôt pas mal, il reste à faire du rangement dans le boitier, peut être mettre un interrupteur principal, eventuellement faire un PCB si je suis pas trop rouillé.  
-
-# Veilleuse
-
-Petit projet de veilleuse pour ma fille. Mais je pense qu'il va y avoir des demandes ;p
-
-### Projet 
-
-Le projet se base sur la [Glowing Moon](https://www.thingiverse.com/thing:2531838) auquel j'ai greffé un arduino nano, des led RGB, une photoresistance. 
-
-
-### BOM 
-
-* Les parties à imprimer en 3D
-* Un arduino nano (ou autre chose)
-* Des leds RGB `ws2812b` ou autre chose supporté par `Adafuit_Neopixel`. Dans mon cas, une barrette de 8 diodes
-* Une resistance de 10kΩ 
-* Un photoresistance 
-
-### Impression 
-
-La lune a été réalisée en PLA Eryone Blanc (sans support, 210°C / 50° / 0.16mm / 20% Gyroid). Le remplissage peut être mis à 100%. C'est en gros, une lithophanie. Pour cette dimension, comptez 26h d'impression
-
-Les pieces de la bases ont été realisées avec du Geeetech Noir Silk, en 0.24mm
-
-![image](assets/IMG_20201016_001532.jpg) ![image](assets/IMG_20201017_101245.jpg)
-
-Je vous ai mis une petite vidéo du résultat final [ici](assets/VID_20201025_135730.mp4)
-
-### Platine de test 
-
-![image](assets/fritzing.png)
-
-
-### Configuration du code
-
-Les principales valeurs à adapter sont les suivantes : 
-
-```c
-// Config Leds
-#define PIN          2
-#define NUMPIXELS    8
-
-// Config Photoresistance
-#define LIGHT_SENSOR A0
-
-// Config couleur
-#define R 255
-#define G 128
-#define B 56
-
-// Config seuil
-#define ON_LEVEL 200
-#define OFF_LEVEL 500
-
-```
-
+> **STATUS** : 20201025 : Ca marche plutôt pas mal, il reste à faire du rangement dans le boitier, peut être mettre un interrupteur principal, eventuellement faire un PCB si je suis pas trop rouillé.  
+
+# Veilleuse
+
+Petit projet de veilleuse pour ma fille. Mais je pense qu'il va y avoir des demandes ;p
+
+### Projet 
+
+Le projet se base sur la [Glowing Moon](https://www.thingiverse.com/thing:2531838) auquel j'ai greffé un arduino nano, des led RGB, une photoresistance. 
+
+
+### BOM 
+
+* Les parties à imprimer en 3D
+* Un arduino nano (ou autre chose)
+* Des leds RGB `ws2812b` ou autre chose supporté par `Adafuit_Neopixel`. Dans mon cas, une barrette de 8 diodes
+* Une resistance de 10kΩ 
+* Un photoresistance 
+
+### Impression 
+
+La lune a été réalisée en PLA Eryone Blanc (sans support, 210°C / 50° / 0.16mm / 20% Gyroid). Le remplissage peut être mis à 100%. C'est en gros, une lithophanie. Pour cette dimension, comptez 26h d'impression
+
+Les pieces de la bases ont été realisées avec du Geeetech Noir Silk, en 0.24mm
+
+![image](assets/IMG_20201016_001532.jpg) ![image](assets/IMG_20201017_101245.jpg)
+
+Je vous ai mis une petite vidéo du résultat final [ici](assets/VID_20201025_135730.mp4)
+
+### Platine de test 
+
+![image](assets/fritzing.png)
+
+
+### Configuration du code
+
+Les principales valeurs à adapter sont les suivantes : 
+
+```c
+// Config Leds
+#define PIN          2
+#define NUMPIXELS    8
+
+// Config Photoresistance
+#define LIGHT_SENSOR A0
+
+// Config couleur
+#define R 255
+#define G 128
+#define B 56
+
+// Config seuil
+#define ON_LEVEL 200
+#define OFF_LEVEL 500
+
+```
+

+ 126 - 125
code/veilleuse/veilleuse.ino

@@ -1,125 +1,126 @@
-// Based on Adafruit Neopixel 'simple' sample
-
-#include <Adafruit_NeoPixel.h>
-
-
-// Config Leds
-#define PIN          2
-#define NUMPIXELS    12
-
-// Config Photoresistance
-#define LIGHT_SENSOR A0
-
-// Config couleur
-#define R 255
-#define G 128
-#define B 56
-
-// Config seuil
-#define ON_LEVEL 50
-#define OFF_LEVEL 100
-
-
-
-Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
-
-
-void lightBoot(int r, int g, int n, int b)
-{
-
-  
-  if ((b < 0) || (b > 255)) {
-    return false;
-  }
-
-  int red = floor((r * b) / 100);
-  int green = floor((g * b) / 100);
-  int blue = floor((b * b) / 100);
-
-  pixels.clear();
-  for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...
-    pixels.setPixelColor(i, pixels.Color(red, green, blue));
-  }
-  pixels.show();   // Send the updated pixel colors to the hardware.
-
-}
-
-void lightLevel(int b)
-{
-  if ((b < 0) || (b > 255)) {
-    return false;
-  }
-
-  int red = floor((R * b) / 100);
-  int green = floor((G * b) / 100);
-  int blue = floor((B * b) / 100);
-
-  pixels.clear();
-  for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...
-    pixels.setPixelColor(i, pixels.Color(red, green, blue));
-  }
-  pixels.show();   // Send the updated pixel colors to the hardware.
-
-}
-
-void lightFadeIn(int d) {
-  pixels.clear();
-  pixels.show();
-  for (int i = 0; i < 100; i ++) {
-    lightLevel(i);
-    delay(d);
-  }
-}
-
-void lightFadeOut(int d) {
-  pixels.clear();
-  pixels.show();
-  for (int i = 100; i >= 0; i --) {
-    lightLevel(i);
-    delay(d);
-  }
-}
-
-
-void setup() {
-  int i;
-  Serial.begin(9600);
-  Serial.println("Booting");
-  pixels.begin();
-  pixels.clear();
-  pixels.show();
-  for (int i = 0; i <=100; i ++) {
-    lightBoot(255,0,0,i);
-    delay(10);
-  }
-  delay(1000);
-  pixels.clear();
-  pixels.show();
-  for (int i = 100; i >= 0; i --) {
-    lightBoot(255,0,0,i);
-    delay(10);
-  }
-  Serial.println("Ready !");
-}
-
-int state = 0;
-
-void loop() {
-  int valeur = analogRead(A0);
-  Serial.println(valeur);
-  if ((valeur > OFF_LEVEL) && (state == 1)) {
-    Serial.print("Switching OFF : val=");
-    Serial.println(valeur);
-    lightFadeOut(50);
-    state = 0;
-  }
-
-  if ((valeur < ON_LEVEL) && (state == 0)) {
-    Serial.print("Switching ON : val=");
-    Serial.println(valeur);
-    lightFadeIn(50);
-    state = 1;
-  }
-  delay(1000);
-
-}
+// Based on Adafruit Neopixel 'simple' sample
+
+#include <Adafruit_NeoPixel.h>
+
+
+// Config Leds
+#define PIN          2
+#define NUMPIXELS    12
+
+// Config Photoresistance
+#define LIGHT_SENSOR A0
+
+// Config couleur
+#define R 255
+#define G 128
+#define B 56
+#define MAXLEVEL 10 // Percent
+
+// Config seuil
+#define ON_LEVEL 50
+#define OFF_LEVEL 100
+
+
+
+Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
+
+
+void lightBoot(int r, int g, int n, int b)
+{
+
+  
+  if ((b < 0) || (b > 255)) {
+    return false;
+  }
+
+  int red = floor((r * b) / 100);
+  int green = floor((g * b) / 100);
+  int blue = floor((b * b) / 100);
+
+  pixels.clear();
+  for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...
+    pixels.setPixelColor(i, pixels.Color(red, green, blue));
+  }
+  pixels.show();   // Send the updated pixel colors to the hardware.
+
+}
+
+void lightLevel(int b)
+{
+  if ((b < 0) || (b > 255)) {
+    return false;
+  }
+
+  int red = floor((R * b) / 100);
+  int green = floor((G * b) / 100);
+  int blue = floor((B * b) / 100);
+
+  pixels.clear();
+  for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...
+    pixels.setPixelColor(i, pixels.Color(red, green, blue));
+  }
+  pixels.show();   // Send the updated pixel colors to the hardware.
+
+}
+
+void lightFadeIn(int d) {
+  pixels.clear();
+  pixels.show();
+  for (int i = 0; i < MAXLEVEL; i ++) {
+    lightLevel(i);
+    delay(d);
+  }
+}
+
+void lightFadeOut(int d) {
+  pixels.clear();
+  pixels.show();
+  for (int i = MAXLEVEL; i >= 0; i --) {
+    lightLevel(i);
+    delay(d);
+  }
+}
+
+
+void setup() {
+  int i;
+  Serial.begin(9600);
+  Serial.println("Booting");
+  pixels.begin();
+  pixels.clear();
+  pixels.show();
+  for (int i = 0; i <=100; i ++) {
+    lightBoot(255,0,0,i);
+    delay(10);
+  }
+  delay(1000);
+  pixels.clear();
+  pixels.show();
+  for (int i = 100; i >= 0; i --) {
+    lightBoot(255,0,0,i);
+    delay(10);
+  }
+  Serial.println("Ready !");
+}
+
+int state = 0;
+
+void loop() {
+  int valeur = analogRead(A0);
+  Serial.println(valeur);
+  if ((valeur > OFF_LEVEL) && (state == 1)) {
+    Serial.print("Switching OFF : val=");
+    Serial.println(valeur);
+    lightFadeOut(50);
+    state = 0;
+  }
+
+  if ((valeur < ON_LEVEL) && (state == 0)) {
+    Serial.print("Switching ON : val=");
+    Serial.println(valeur);
+    lightFadeIn(50);
+    state = 1;
+  }
+  delay(1000);
+
+}

+ 14 - 14
stl/README.md

@@ -1,14 +1,14 @@
-# STL Veilleuse
-
-Modèles Thingverse : 
-
-* [Glowing Moon](https://www.thingiverse.com/thing:2531838)
-* [Glowing Moon Lamp Base](https://www.thingiverse.com/thing:2746894)
-
-> Le repertoine `thingiverse`contient une copie pour archive des deux modèles. Cependant, je vous conseille de vous baser sur les versions présentes sur Thingiverse.
-
-Modèle Customs : 
-
-* [Base Murale](./stl/base-murale.stl)
-* [Capot Inférieur -- WIP](./stl/capot.stl)
-
+# STL Veilleuse
+
+Modèles Thingverse : 
+
+* [Glowing Moon](https://www.thingiverse.com/thing:2531838)
+* [Glowing Moon Lamp Base](https://www.thingiverse.com/thing:2746894)
+
+> Le repertoine `thingiverse`contient une copie pour archive des deux modèles. Cependant, je vous conseille de vous baser sur les versions présentes sur Thingiverse.
+
+Modèle Customs : 
+
+* [Base Murale](./stl/base-murale.stl)
+* [Capot Inférieur -- WIP](./stl/capot.stl)
+