Nicht mehr lange und ich muss mein Schulprojekt abgeben. Jedoch, funktioniert mein Programm nicht. Ich versuche seit Tagen den Fehler zu beheben jedoch ohne Erfolg.
Mein Ziel: Einen Attiny45 zu Programmieren mit einem Uno als Programmer und der Arduino Software.
Geplant ist ein Blinker der ab einen bestimmten Winkel einschalten soll.
Der Sketchfehler:
C:\Users\admin\Desktop\SchulProjeckt\sketch_schulProjekt\sketch_schulProjekt.ino: In function 'void loop()':
sketch_schulProjekt:18:4: error: 'Serial' was not declared in this scope
Serial.println(Db);
^
exit status 1
'Serial' was not declared in this scope
Setze Deinen Code bitte in Codetags (</>-Button oben links im Forumseditor oder [code] davor und [/code] dahinter ohne *).
Das kannst Du auch noch nachträglich ändern.
Außerdem hat der Attiny 45 keine serielle Schnittstelle.
habe mir erlaubt etwas aufzuräumen, vorallendingen das Blinken in eine Funktion auszulagern.
Entferne am Ende alle nicht benötigten globalen Variablen.
Variablen für Zeitvergleiche mit millis u.ä. immer unsigned.
Für Pins sollte man immer const byte verwenden. Hat sich bewährt.
const byte pin_Sens = 4;
const byte pin_LED = 1;
int Db;
bool Blink = false;
unsigned int Blink_time = 0;
void setup()
{
Serial.begin(9600);
pinMode (pin_Sens, INPUT_PULLUP);
pinMode(pin_LED, OUTPUT);
}
void loop()
{
Serial.println(Db);
if (digitalRead(pin_Sens) == LOW) {
Db = 0;
}
else {
Db++;
}
if (Db < 200) {
Blink = true;
} else {
Db = 200;
Blink = false;
//digitalWrite(LED_BUILTIN, LOW);
}
if (Blink == true) {
blink_LED(500);
}
else {
digitalWrite(pin_LED, LOW);
}
}
// ****** Funktionen ****** //
void blink_LED (unsigned int interval)
{
static bool ledState = LOW;
static unsigned long previousMillis = 0;
if (millis() - previousMillis >= interval) {
previousMillis = millis(); // save the last time you blinked the LED
ledState = !ledState; // if the LED is off turn it on and vice-versa:
digitalWrite(pin_LED, ledState);
}
}