Les vidéos youtube ne posent quant à, elles pas de probléme... Un problème avec Viméo ???
Sinon, je mets à disposition le code que j'ai injecté dans l'attiny85 avec un bouton poussoir.
Le code est configuré pour 4 modes, 3 modes de flash de couleurs différentes et un mode OFF.
Vous pouvez sans problème augmenter / diminuer le nombre de modes.
Concernant le montage :
- la Pin 0 de l'attiny est connectée au Gnd lorsque l'on appuie sur le bouton poussoir (Je n'ai pas mis de résistance, je vais voir si à la longue ça pose problème, mais pour l'instant c'est okey)
- la Pin 1 de l'attiny est la pin pour le contrôle des leds.
Pour faciliter le montage, j'ai utilisé les pins des 2 bords des neopixels : cf la vidéo.
Pour la programmation de L'attiny, j'ai suivi ce tuto :
http://www.kobakant.at/DIY/?p=3742" onclick="window.open(this.href);return false;
qui explique le même process que le tuto trouvé par willmodelisme.
Voici le code en utilisant la bibliothèque Adafruit.
Code : Tout sélectionner
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#define DATA_PIN 1 //output pin on ATTiny85
#define NUMPIXELS 8 // How many NeoPixels are attached to the Arduino?
#define BTN_PIN 0 //input pin on ATTiny85
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, DATA_PIN, NEO_GRB + NEO_KHZ800);
// PushButton Stat
boolean PushButtonStat = false;
// PushbuttonPin
const int PushbuttonPin = 0; // 0 For Attiny
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
int NumberOfMode = 4; // 3 + 1 mode OFF
long PushButtonpreviousMillis = 0;
unsigned long currentMillis = 0;
long Pushinterval = 750;
long blinkMillis = 200; // Blinker delay
// Color Set Mode 1
int R = 0;
int G = 250;
int B = 0;
// Color Set Mode 2
int R_2 = 250;
int G_2 = 0;
int B_2 = 0;
// Color Set Mode 3
int R_3 = 0;
int G_3 = 0;
int B_3 = 250;
long FirstcurrentMillis = 0;
long FirstpreviousMillis = 0;
int ledState = LOW;
// Program Start //
void setup() {
pinMode(PushbuttonPin, INPUT_PULLUP); // initialize the button pin as a input:
// Serial.begin(9600); // initialize serial communication:
pixels.begin(); // This initializes the NeoPixel library.
}
void loop() {
currentMillis = millis();
// Push Button Counter
if(currentMillis - PushButtonpreviousMillis > Pushinterval)
{
buttonState = digitalRead(PushbuttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState)
{
// if the state has changed, increment the counter
if (buttonState == HIGH)
{
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
// Serial.println("on");
// Serial.print("number of button pushes: ");
//Serial.println(buttonPushCounter);
}
else
{
// if the current state is LOW then the button
// wend from on to off:
// Serial.println("off");
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
if (buttonPushCounter == NumberOfMode)
{
buttonPushCounter = 0; // reset buttonPushCounter
}
} // Push Button Counter
//***************** Start Modes **********************//
switch (buttonPushCounter)
{
case 0:
for (int i = 0; i<NUMPIXELS; i++)
{
pixels.setPixelColor(i, pixels.Color(0,0,0)); // All Leds OFF.
pixels.show(); // This sends the updated pixel color to the hardware.
}
break;
case 1 : // Blink Mode Green
FirstcurrentMillis = millis();
if(FirstcurrentMillis - FirstpreviousMillis > blinkMillis)
{
FirstpreviousMillis = FirstcurrentMillis;
if (ledState == LOW)
{
for (int i = 0; i<NUMPIXELS; i++)
{
pixels.setPixelColor(i, pixels.Color(R,G,B));
pixels.show(); // This sends the updated pixel color to the hardware.
ledState = HIGH;
}
}
else
{
for (int i = 0; i<NUMPIXELS; i++)
{
pixels.setPixelColor(i, pixels.Color(0,0,0));
pixels.show(); // This sends the updated pixel color to the hardware.
ledState = LOW;
}
}
}
break;
case 2 : // Blink Mode Red
FirstcurrentMillis = millis();
if(FirstcurrentMillis - FirstpreviousMillis > blinkMillis)
{
FirstpreviousMillis = FirstcurrentMillis;
if (ledState == LOW)
{
for (int i = 0; i<NUMPIXELS; i++)
{
pixels.setPixelColor(i, pixels.Color(R_2,G_2,B_2));
pixels.show(); // This sends the updated pixel color to the hardware.
ledState = HIGH;
}
}
else
{
for (int i = 0; i<NUMPIXELS; i++)
{
pixels.setPixelColor(i, pixels.Color(0,0,0));
pixels.show(); // This sends the updated pixel color to the hardware.
ledState = LOW;
}
}
}
break;
case 3 : // Blink Mode Blu
FirstcurrentMillis = millis();
if(FirstcurrentMillis - FirstpreviousMillis > blinkMillis)
{
FirstpreviousMillis = FirstcurrentMillis;
if (ledState == LOW)
{
for (int i = 0; i<NUMPIXELS; i++)
{
pixels.setPixelColor(i, pixels.Color(R_3,G_3,B_3));
pixels.show(); // This sends the updated pixel color to the hardware.
ledState = HIGH;
}
}
else
{
for (int i = 0; i<NUMPIXELS; i++)
{
pixels.setPixelColor(i, pixels.Color(0,0,0));
pixels.show(); // This sends the updated pixel color to the hardware.
ledState = LOW;
}
}
}
break;
} // end of loop
}
Tom