Guten Abend und hallo an alle hier,
ich bastle jetzt schon einige zeit mit meinem arduino micro herum und kapituliere jetzt vor meinem problem.
und zwar wollte ich nur mit einem taster einzelne programme ansteuern. zuerst soll die led grün, beim zweiten tastendruck zb blau usw leuchten. irgendwann soll dann eine automatikprogramm ausgewählt werden.
mein problem ist es eine solche farbwechselautomatik zu programmieren, die auch mit einem tastendruck wieder verlassen werden kann.
mein letzter stand ist eine switch case abfrage bei der nach 4x taster drücken zu der farbwechselfunktion gesprungen werden soll. der code sieht in etwa so aus:
byte counterx=0;
byte countery=0;
byte counterz=63;
byte changeMarkerx;
byte changeMarkery;
byte changeMarkerz;
int taster=3;
int tasterWert=0;
int vorhertasterWert=0;
int zaehler=0;
byte starter=0;
int tasterzaehler;
#include <Adafruit_NeoPixel.h>
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 6
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 1
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
unsigned long prev;
int farbwechselinterval=15;
int bounceinterval=50;
void setup() {
pixels.begin(); // This initializes the NeoPixel library.
pixels.show();
prev=millis();
pinMode(taster,INPUT);
}
void loop() {
tasterWert=digitalRead(taster);
if (vorhertasterWert!= tasterWert)
{
if(tasterWert==HIGH)
{
if( (millis()-prev)>bounceinterval){
prev=millis();
tasterzaehler++;
if (tasterzaehler>4)
tasterzaehler=0;
modus(tasterzaehler);
}
}
}
vorhertasterWert=tasterWert;
}
void modus(int i) {
byte a;
byte b;
byte c;
switch (i){
case 0 : a=0; b=0; c=0; break;
case 1 : a=255; b=0; c=0; break;
case 2 : a=0; b=255; c=0; break;
case 3 : a=0; b=0; c=255; break;
case 4 : farbwechsel(); break;
}
for(int i=0;i<NUMPIXELS;i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(a,b,c));
pixels.show(); // This sends the updated pixel color to the hardware.
}
}
void farbwechsel(){
int loga[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
16, 18, 20, 22, 25, 28, 30, 33, 36, 39, 42, 46, 49, 53, 56, 60,
64, 68, 72, 77, 81, 86, 90, 95, 100, 105, 110, 116, 121, 127, 132,
138, 144, 150, 156, 163, 169, 176, 182, 189, 196, 203, 210, 218,
225, 233, 240, 248, 255};
byte x;
byte y;
byte z;
if ((millis()-prev) > farbwechselinterval)
{
prev=millis();
if(countery==0 && counterz==63)
counterx++;
if (counterx==63 && countery==0)
counterz--;
if (counterx==63 && counterz==0)
countery++;
if (countery==63 && counterz==0)
counterx--;
if (counterx==0 && countery==63)
counterz++;
if (counterz==63 && counterx==0)
countery--;
}
x= counterx[loga];
y= countery[loga];
z= counterz[loga];
for(int i=0;i<NUMPIXELS;i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(x,y,z)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
}
}
es ist wohl nur ein teil des codes wichtig aber ich hoffe ich mache es euch leichter so meine gedankengänge zu verstehen, leider gehen mir mittlerweile die ideen aus was ich noch probieren könnte.
anscheinend wird void farbwechsel() gar nicht abgefragt, es passiert jedenfalls nicht der erwartete farbwechseleffekt, sondern eine eventuell zufällige grüne farbe wird erzeugt.
entschuldigt den aufsatz, ich bin für jede hilfe sehr dankbar.
mit freundlichen grüßen,
blobfisch