#include <Wire.h>
#include <avr/sleep.h>
//Overige Variabelen en PIN Layout
//led
//Declareren Eindswitch
int switchPin = 12;
int ledPin = LED_BUILTIN;
int switchState = LOW;
//Eind declaren Eindswitch
const int buzzer = 6;
//Setup sketch
void setup() {
//Serial.begin(9600);
pinMode(4, OUTPUT); //relais
digitalWrite(4, HIGH);
pinMode(10, OUTPUT);
pinMode(buzzer, OUTPUT);
//sleep modus bepalen
// see below for sleep modes
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
/*
For idle (slight reduction in power): SLEEP_MODE_IDLE
For standby (more reduction in power): SLEEP_MODE_STANDBY
For power-down (most reduction in power): SLEEP_MODE_PWR_DOWN
*/
//End sleep modus
//Setup Eindswitch
pinMode(ledPin, OUTPUT); // voorlopig laten staan
pinMode(switchPin, INPUT);
//Eind setup Eindswitch
}
void clr_error() { // zet alles terug op nul
digitalWrite(4, LOW);
digitalWrite(10, LOW);
noTone(buzzer);
}
// EINDSWITCH HIGH AFHANDELING
void endswitch_high() {
// Aanroepen in geval eindswitch
tone(buzzer, 3000); //Toontje spelen
delay(500);
noTone(buzzer);
/*
digitalWrite(10, HIGH); // LED
delay(10000);
digitalWrite(4, LOW); // RELAIS
*/
system_sleep(); // TEST !!!
}
// EINDE EINDSWITCH HIGH AFHANDELING
//Slaap modus loop
void system_sleep(){
//Slaap modus inschakelen
delay(10000);
digitalWrite(4, LOW); // Relais
sleep_mode();
//End Slaap modus
}
void loop() {
//Eindswitch Detectie
switchState = digitalRead(switchPin);
// Serial.print("Status Eindswitch: "); // alleen voor test doeleinden
//Serial.println(switchState);
if (switchState == HIGH) {
digitalWrite(ledPin, HIGH);
//Serial.println("Eindswitch HIGH ");
endswitch_high(); //aanroepen eindswitch high actie
} else {
digitalWrite(ledPin, LOW);
//Serial.println("Eindswitch LOW ");
}
//Einde Eindswitch loop
//delay(500);
}
Printer uit
Reset
Eindswitch
Hoofd relais
Printer AAN/UIT
3D Printer dummy