bh3a-Icetruck-Challenge-1-3/Arduino/challenge1_aktors/challenge1_aktors.ino

84 lines
1.5 KiB
Arduino
Raw Normal View History

2024-06-27 11:51:06 +02:00
#include <Servo.h>
#include <Wire.h>
#define Luefter 7
#define Gasklappe 5
#define NotfallButton 4
Servo kuehlklappe;
void cooling(){
int pos;
for (pos = 0; pos <= 180; pos += 1) {
kuehlklappe.write(pos);
delay(10);
}
delay(1000);
for (pos = 180; pos >= 0; pos -= 1) {
kuehlklappe.write(pos);
delay(10);
}
}
void setup() {
kuehlklappe.attach(Gasklappe);
pinMode(Luefter, OUTPUT);
pinMode(NotfallButton, INPUT);
Serial.begin(9600);
Wire.begin(0x8);
Wire.onReceive(receiveEvent);
}
void receiveEvent(int howMany) {
while (Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
}
}
uint8_t var = 0 ;
uint8_t fan = 0 ;
void loop() {
if ((Serial.available() > 0)||(Wire.available())){
char Letter;
if (Serial.available() > 0){
Letter = Serial.read();
}
if (Wire.available()){
Letter = Wire.read();
}
Serial.println (Letter, DEC);
//Serial.println(Letter ,DEC);
if ( (Letter == 'V') || (Letter == 'v')){
var =1;
Serial.println("Ventile opened");
}
else{
var =0;
}
if (Letter == 'F'){
fan = 1;
Serial.println("Luefter eingeschaltet");
}
if (Letter == 'f'){
fan = 0;
Serial.println("Luefter ausgeschaltet");
}
}
else{
var = digitalRead(NotfallButton);
}
if (var) cooling();
}