belgarion:
zumindest schmeißt er mir dann jedesmal ne fehlermeldung raus "rainbow was not declared".
Klassiker!
Du versuchst eine Funktion aufzurufen, die angeblich nicht deklariert ist.
Da ich die Funktion selbst (um-)geschrieben habe und davon ausgehe, das die sonst auch funktioniert, hier der ultimative Tipp:
Drücke einmal STRG-T in der Arduino-IDE.
Jetzt wirst Du irgendwo } auf selber Höhe haben, ohne das es vorher eine öffnende { gab.
Sieht dann (stark gekürzt) so aus.
Mein Sketch der die Fehlermeldung erzwingt:
void setup()
{}
void loop()
{
rainbow(100);
}
}
void rainbow(int wait)
{
static long firstPixelHue = 0;
static unsigned long lastmillis = millis();
if (millis() - lastmillis > wait)
{
firstPixelHue += 256;
if (firstPixelHue >= 5 * 65536) firstPixelHue = 0;
for (int i = 0; i < strip.numPixels(); i++)
{ // For each pixel in strip...
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
}
strip.show(); // Update strip with new contents
lastmillis = millis();
}
}
}
Meine Fehlermeldung, die Deiner entspricht:
/tmp/arduino_modified_sketch_68646/sketch_mar10a.ino: In function 'void loop()':
sketch_mar10a:5:14: error: 'rainbow' was not declared in this scope
rainbow(100);
^
/tmp/arduino_modified_sketch_68646/sketch_mar10a.ino: At global scope:
sketch_mar10a:7:1: error: expected declaration before '}' token
}
^
exit status 1
'rainbow' was not declared in this scope
WICHTIG!
ICH kenn das. Wenn Du sowas hast, gehört
1.) Selber nachgesehen, wo und wie das angemeckert wird. Dazu sind die vollständigen Meldungen beim kompilieren unter den Voreinstellungen zu aktivieren. (Vorher STRG-T!!!)
2.) Die komplette Fehlerausgabe (also alles was rot ist) UND den Code hier einstellen, damit man helfen kann....
Hey Danke dass du mir so weiter hilfst. Das mit dem STRG+T hätte ich mal versuchen sollen bevor ich das schonwieder komplett umgebaut habe...
Wollte es jetzt mit einem interrupt versuchen. Aber irgendwie komm ich damit auch nich zurecht. Hab versucht mein Programm anhand dieser "Anleitung" (https://hikro.de/arduino-taster-als-schalter-programmieren) umzubauen und auch versucht das nachzuvollziehen. Allerdings schmeißt er mir da natürlich auch ordentlich fehler raus...
Sketch wird kompiliert...
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "-IC:\\Users\\Martin\\Documents\\Arduino\\libraries\\Adafruit_NeoPixel" "C:\\Users\\Martin\\AppData\\Local\\Temp\\arduino_build_153733\\sketch\\strandtest_modifiziert_millis_touch.ino.cpp" -o "C:\\Users\\Martin\\AppData\\Local\\Temp\\arduino_build_153733\\sketch\\strandtest_modifiziert_millis_touch.ino.cpp.o"
strandtest_modifiziert_millis_touch:41:16: error: expected constructor, destructor, or type conversion before '(' token
attachInterrupt( 0, interruptFunktion, LOW); // aktivierung des Interrupts
^
strandtest_modifiziert_millis_touch:43:1: error: expected declaration before '}' token
}
^
Bibliothek Adafruit_NeoPixel in Version 1.7.0 im Ordner: C:\Users\Martin\Documents\Arduino\libraries\Adafruit_NeoPixel wird verwendet
exit status 1
expected constructor, destructor, or type conversion before '(' token
Und der Code lautet:
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#endif
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN 6
bool geschaltet = false;
int TasterPin = 2;
int LedPin = 6;
int empfindlichkeit = 200;
// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 60
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
unsigned long anzeit = 1 * 60UL * 60UL * 1000UL; // Stunden*Minute*Sekunde*1000ms
// setup() function -- runs once at startup --------------------------------
void setup() {
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
pinMode(LedPin, OUTPUT);
pinMode(TasterPin, INPUT_PULLUP);
}
// loop() function -- runs repeatedly as long as board is on ---------------
attachInterrupt( 0, interruptFunktion, LOW); // aktivierung des Interrupts
void loop() {
if (geschaltet == true) {
digitalwrite(LedPin, HIGH);
if ((millis() < anzeit))
{
// Fill along the length of the strip in various colors...
rainbow(100); // Flowing rainbow cycle along the whole strip
}
else {
strip.setBrightness(0);
strip.show();
}
}
if (geschaltet == false) {
digitalWrite(LedPin, LOW);
}
}
void interruptFunction() {
if ( millis() > (letzteZeit + entprellWert)) {
if (geschaltet == false) {
geschaltet = true;
if ((millis() < anzeit))
{
// Fill along the length of the strip in various colors...
rainbow(100); // Flowing rainbow cycle along the whole strip
}
else {
strip.setBrightness(0);
strip.show();
}
}
else {
geschaltet = false;
strip.setBrightness(0);
strip.show();
}
letzteZeit = millis();
}
}
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
void rainbow(int wait) {
static long firstPixelHue = 0;
static unsigned long lastmillis = millis();
if (millis() - lastmillis > wait)
{
firstPixelHue += 256;
if (firstPixelHue >= 5 * 65536) firstPixelHue = 0;
for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
}
strip.show(); // Update strip with new contents
lastmillis = millis();
}
}
expected constructor, destructor, or type conversion before '(' token
Selbes Problem.
Jetzt hast Du nicht zwei }} sondern gar keine!
// loop() function -- runs repeatedly as long as board is on ---------------
attachInterrupt( 0, interruptFunktion, LOW); // aktivierung des Interrupts
void loop() {