Add few files
This commit is contained in:
parent
e4c6d26e4e
commit
8531a8d79f
120
Arduino/Challenge1_sensors/Challenge1_sensors.ino
Normal file
120
Arduino/Challenge1_sensors/Challenge1_sensors.ino
Normal file
|
@ -0,0 +1,120 @@
|
|||
#include <dht.h>
|
||||
#include <U8g2lib.h>
|
||||
#include <Wire.h>
|
||||
#include <Arduino.h>
|
||||
#define SLAVE_ADDRESS 0x0b
|
||||
|
||||
dht DHT;
|
||||
|
||||
#define DHT11_PIN 9
|
||||
|
||||
const int red = 7;
|
||||
const int green = 6;
|
||||
const int yellow = 5;
|
||||
|
||||
// U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ A5, /* data=*/ A4);
|
||||
|
||||
void setup(){
|
||||
|
||||
pinMode(red, OUTPUT);
|
||||
pinMode(green, OUTPUT);
|
||||
pinMode(yellow, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
// u8g2.begin();
|
||||
Wire.begin(SLAVE_ADDRESS);
|
||||
Wire.onRequest(sendtemperature);
|
||||
}
|
||||
|
||||
float temperature(uint16_t pin){
|
||||
float temp = 0;
|
||||
int chk = DHT.read11(pin);
|
||||
temp = DHT.temperature;
|
||||
return temp;
|
||||
}
|
||||
|
||||
float humidity(uint16_t pin){
|
||||
float hum = 0;
|
||||
int chk = DHT.read11(pin);
|
||||
hum = DHT.humidity;
|
||||
return hum;
|
||||
}
|
||||
void set_state(uint8_t state){
|
||||
digitalWrite(green,0);
|
||||
digitalWrite(red,0);
|
||||
digitalWrite(yellow,0);
|
||||
switch (state){
|
||||
case 0: digitalWrite(green,1); break;
|
||||
case 1: digitalWrite(red,1); break;
|
||||
case 2: digitalWrite(yellow,1); break;
|
||||
default:;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void print4plotter(float temp,float hum){
|
||||
Serial.print("Temperatur:");
|
||||
Serial.print(temp);
|
||||
Serial.print(", Humidity:");
|
||||
Serial.println(hum);
|
||||
}
|
||||
|
||||
/*
|
||||
void print_screen_temp(float temp){
|
||||
u8g2.clearBuffer();
|
||||
u8g2.setFont(u8g2_font_unifont_t_symbols);
|
||||
u8g2.setFontRefHeightExtendedText();
|
||||
u8g2.setDrawColor(1);
|
||||
u8g2.setFontPosTop();
|
||||
u8g2.setFontDirection(0);
|
||||
u8g2.drawStr( 0, 0, "Temperatur:");
|
||||
char buff[6];
|
||||
dtostrf(temp, 4, 2, buff);
|
||||
u8g2.drawStr( 0, 18, buff);
|
||||
u8g2.drawUTF8(40, 18, "°C");
|
||||
u8g2.sendBuffer();
|
||||
}
|
||||
|
||||
void print_screen_hum(float hum){
|
||||
u8g2.clearBuffer();
|
||||
u8g2.setFont(u8g2_font_unifont_t_symbols);
|
||||
u8g2.setFontRefHeightExtendedText();
|
||||
u8g2.setDrawColor(1);
|
||||
u8g2.setFontPosTop();
|
||||
u8g2.setFontDirection(0);
|
||||
u8g2.drawStr( 0, 0, "Humidity:");
|
||||
char buff[6];
|
||||
dtostrf(hum, 4, 2, buff);
|
||||
u8g2.drawStr( 0, 18, buff);
|
||||
u8g2.drawUTF8(40, 18, "%");
|
||||
u8g2.sendBuffer();
|
||||
}
|
||||
*/
|
||||
|
||||
uint8_t converttemp(float temp){
|
||||
temp += 75;
|
||||
return round(temp);
|
||||
}
|
||||
float gtemp = 0;
|
||||
|
||||
void sendtemperature(){
|
||||
uint8_t dat = converttemp(gtemp);
|
||||
Wire.write(dat);
|
||||
}
|
||||
uint32_t d_state = 0;
|
||||
uint32_t display_time=10000;
|
||||
uint32_t messure_time=100;
|
||||
void loop() {
|
||||
for (int i=0; i< display_time/messure_time; i++){
|
||||
float temp=temperature(DHT11_PIN);
|
||||
float hum= humidity(DHT11_PIN);
|
||||
print4plotter(temp,hum);
|
||||
gtemp = temp;
|
||||
if (temp<=0) set_state(0); // green
|
||||
else if (temp <=40) set_state(2); // yellow
|
||||
else set_state(1); // red
|
||||
//if (d_state % 2) print_screen_temp(temp);
|
||||
//else print_screen_hum(hum);
|
||||
delay(messure_time);
|
||||
}
|
||||
d_state ++;
|
||||
}
|
83
Arduino/challenge1_aktors/challenge1_aktors.ino
Normal file
83
Arduino/challenge1_aktors/challenge1_aktors.ino
Normal file
|
@ -0,0 +1,83 @@
|
|||
#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();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in a new issue