Hjälp att få NeoPixlar att fadea i if-sats
Postat: 29 december 2016, 17:02:03
Hej,
Håller på att skriva kod i Arduino IDE för programmering av en ATtiny 85 som skall styra två NeoPixlar i en sensor som skall ändra färg vid olika situationer
När temperaturen i rummet understiger inställt värde skall den t.ex. lysa blått.
När jag styr temperaturen (Börvärdet) via Z-Wave skall den lysa Mangenta i en halv sek var 5 sek osv.
Bifogar min kod nedan som tänder och släcker NeoPixeln digital av och på. Har nu försökt att få till en funktion att få NeoPixeln att fadea upp och ner till inställt värde. Har tittat på andra projekt och förstått att det skall vara en funktion av typ [for(int k = 0; k < 256; k++))]. Har dock inte lyckats få den att fungera i min if-sats.
Någon som har några kloka råd?
KOD:
const int BluePin = 2;
const int Blue_MangentaPin = 1;
const int MangentaPin = 0;
const int RedPin = 3;
//variabel för att avläsa ingångsstatus
int BlueState = 0;
int Blue_MangentaState = 0;
int MangentaState = 0;
int RedState = 0;
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
const int NeoPIN = 4;
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 2
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, NeoPIN, NEO_RGB + NEO_KHZ800);
int delayval = 500; // delay
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
pixels.begin(); // This initializes the NeoPixel library.
pixels.show(); // initialize all pixels to "off"
pinMode(BluePin, INPUT);
pinMode(Blue_MangentaPin, INPUT);
pinMode(MangentaPin, INPUT);
pinMode(RedPin, INPUT);
}
void loop() {
BlueState = digitalRead(BluePin);
Blue_MangentaState = digitalRead(Blue_MangentaPin);
MangentaState = digitalRead(MangentaPin);
RedState = digitalRead(RedPin);
if (BlueState == HIGH && Blue_MangentaState == LOW && MangentaState == LOW && RedState == LOW) {
pixels.setPixelColor(0, pixels.Color(0,0,15)); // Blå färg.
pixels.setPixelColor(1, pixels.Color(0,0,15)); // Blå färg.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
if (BlueState == LOW && Blue_MangentaState == HIGH && MangentaState == LOW && RedState == LOW) {
pixels.setPixelColor(0, pixels.Color(0,0,15)); // Blå
pixels.setPixelColor(1, pixels.Color(0,0,15)); // Blå
pixels.show(); // This sends the updated pixel color to the hardware.
delay(5000);
pixels.setPixelColor(0, pixels.Color(15,0,15)); // Mangenta
pixels.setPixelColor(1, pixels.Color(15,0,15)); // Mangenta
pixels.show(); // This sends the updated pixel color to the hardware.
delay(500);
}
if (BlueState == LOW && Blue_MangentaState == LOW && MangentaState == HIGH && RedState == LOW) {
pixels.setPixelColor(0, pixels.Color(15,0,15)); // Mangenta
pixels.setPixelColor(1, pixels.Color(0,0,0));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(3000);
pixels.setPixelColor(0, pixels.Color(0,0,0));
pixels.setPixelColor(1, pixels.Color(15,0,15)); // Mangenta
pixels.show(); // This sends the updated pixel color to the hardware.
delay(3000);
}
if (BlueState == LOW && Blue_MangentaState == LOW && MangentaState == LOW && RedState == HIGH) {
pixels.setPixelColor(0, pixels.Color(15,0,0)); // Röd
pixels.setPixelColor(1, pixels.Color(0,0,0)); //
pixels.show(); // This sends the updated pixel color to the hardware.
delay(50);
pixels.setPixelColor(0, pixels.Color(0,0,0)); // .
pixels.setPixelColor(1, pixels.Color(15,0,0)); // Röd
pixels.show(); // This sends the updated pixel color to the hardware.
delay(50);
}
else {
pixels.setPixelColor(0, pixels.Color(0,0,0));
pixels.setPixelColor(1, pixels.Color(0,0,0));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
Håller på att skriva kod i Arduino IDE för programmering av en ATtiny 85 som skall styra två NeoPixlar i en sensor som skall ändra färg vid olika situationer
När temperaturen i rummet understiger inställt värde skall den t.ex. lysa blått.
När jag styr temperaturen (Börvärdet) via Z-Wave skall den lysa Mangenta i en halv sek var 5 sek osv.
Bifogar min kod nedan som tänder och släcker NeoPixeln digital av och på. Har nu försökt att få till en funktion att få NeoPixeln att fadea upp och ner till inställt värde. Har tittat på andra projekt och förstått att det skall vara en funktion av typ [for(int k = 0; k < 256; k++))]. Har dock inte lyckats få den att fungera i min if-sats.
Någon som har några kloka råd?
KOD:
const int BluePin = 2;
const int Blue_MangentaPin = 1;
const int MangentaPin = 0;
const int RedPin = 3;
//variabel för att avläsa ingångsstatus
int BlueState = 0;
int Blue_MangentaState = 0;
int MangentaState = 0;
int RedState = 0;
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
const int NeoPIN = 4;
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 2
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, NeoPIN, NEO_RGB + NEO_KHZ800);
int delayval = 500; // delay
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
pixels.begin(); // This initializes the NeoPixel library.
pixels.show(); // initialize all pixels to "off"
pinMode(BluePin, INPUT);
pinMode(Blue_MangentaPin, INPUT);
pinMode(MangentaPin, INPUT);
pinMode(RedPin, INPUT);
}
void loop() {
BlueState = digitalRead(BluePin);
Blue_MangentaState = digitalRead(Blue_MangentaPin);
MangentaState = digitalRead(MangentaPin);
RedState = digitalRead(RedPin);
if (BlueState == HIGH && Blue_MangentaState == LOW && MangentaState == LOW && RedState == LOW) {
pixels.setPixelColor(0, pixels.Color(0,0,15)); // Blå färg.
pixels.setPixelColor(1, pixels.Color(0,0,15)); // Blå färg.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
if (BlueState == LOW && Blue_MangentaState == HIGH && MangentaState == LOW && RedState == LOW) {
pixels.setPixelColor(0, pixels.Color(0,0,15)); // Blå
pixels.setPixelColor(1, pixels.Color(0,0,15)); // Blå
pixels.show(); // This sends the updated pixel color to the hardware.
delay(5000);
pixels.setPixelColor(0, pixels.Color(15,0,15)); // Mangenta
pixels.setPixelColor(1, pixels.Color(15,0,15)); // Mangenta
pixels.show(); // This sends the updated pixel color to the hardware.
delay(500);
}
if (BlueState == LOW && Blue_MangentaState == LOW && MangentaState == HIGH && RedState == LOW) {
pixels.setPixelColor(0, pixels.Color(15,0,15)); // Mangenta
pixels.setPixelColor(1, pixels.Color(0,0,0));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(3000);
pixels.setPixelColor(0, pixels.Color(0,0,0));
pixels.setPixelColor(1, pixels.Color(15,0,15)); // Mangenta
pixels.show(); // This sends the updated pixel color to the hardware.
delay(3000);
}
if (BlueState == LOW && Blue_MangentaState == LOW && MangentaState == LOW && RedState == HIGH) {
pixels.setPixelColor(0, pixels.Color(15,0,0)); // Röd
pixels.setPixelColor(1, pixels.Color(0,0,0)); //
pixels.show(); // This sends the updated pixel color to the hardware.
delay(50);
pixels.setPixelColor(0, pixels.Color(0,0,0)); // .
pixels.setPixelColor(1, pixels.Color(15,0,0)); // Röd
pixels.show(); // This sends the updated pixel color to the hardware.
delay(50);
}
else {
pixels.setPixelColor(0, pixels.Color(0,0,0));
pixels.setPixelColor(1, pixels.Color(0,0,0));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}