Gruppe Tobias Eric Yannick Bendikt
Auto:
#include
#include
LiquidCrystal_I2C lcd(0x27, 16, 2);
short motorL_1 = 5; //Motor L vorwärts A1_A
short motorL_2 = 6; //Motor L rückwärts A1_B
short motorR_1 = 10; //Motor R vorwärts B1_A
short motorR_2 = 11; //Motor R rückwärts B1_B
short v = 245;
short v2 = 183;
int t = 1700;
const int TrigPin = 2;
const int EchoPin = 3;
float cm;
float cmmin =15;
int led_max = 13;
int led_min = 12;
int milistart;
int milis;
int milis2 = 0;
int Phase;
int drehen=1000;
int fahren;
void setup()
{
Serial.begin(9600);
pinMode(motorL_1, OUTPUT);
pinMode(motorL_2, OUTPUT);
pinMode(motorR_1, OUTPUT);
pinMode(motorR_2, OUTPUT);
pinMode(led_max , OUTPUT);
pinMode(led_min , OUTPUT);
pinMode(TrigPin, OUTPUT);
pinMode(EchoPin, INPUT);
Phase=1;
// fahren( 0, 0 );
lcd.begin();
}
void loop()
{
lcd.setCursor(0,0);
lcd.print(" Die Entfernung:");
lcd.setCursor(0,1);
lcd.print(cm);
if (Phase==1){
/*Anfang Abstandsmessung */
milistart = millis();
digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);
cm = pulseIn(EchoPin, HIGH) / 58.0;
cm = (int(cm * 100.0)) / 100.0;
Serial.print(cm);
Serial.print("cm");
Serial.println();
/*Ende Abstandsmessung*/
/*Anfang Auto
Phase1( v, v2 );
Phase2( -v, -v2 );
Phase3( v, -v2 ); */
if (cm < cmmin){
Phase=2;
}
if (Phase==2){
milis2=milis;
if (milis>500){
Phase=3;
}
}
if (Phase==3){
milis2=milis;
if (milis>drehen){
Phase=1;
}
}
}
}
if ( Phase==1){
fahren (v,v2);
}
if ( Phase==2){
fahren (-v,-v2);
}
if ( Phase==3){
fahren (v,-v2);
}
}
void fahren(int links, int rechts) {
if(links != 0 || rechts != 0){
Serial.print("Links: ");
Serial.print(links);
Serial.print(" Rechts: ");
Serial.println(rechts);
}
if(links < 0){
links = -links;
analogWrite(motorL_1, 0);
analogWrite(motorL_2, links);
}else{
analogWrite(motorL_1, links);
analogWrite(motorL_2, 0);
}
if(rechts < 0){
rechts = -rechts;
analogWrite(motorR_1, 0);
analogWrite(motorR_2, rechts);
}else{
analogWrite(motorR_1, rechts);
analogWrite(motorR_2, 0);
}
/*Ende Auto*/
}
HUMBA!!!
#include
#include
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
lcd.begin();
}
void loop()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Gib mir ein:");
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("H");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("U");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("M");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("B");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("A");
delay(2000);lcd.clear();
lcd.setCursor(0,0);
lcd.print("AUSRUFEZEICHEN");
delay(4000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("UND WIR SINGEN");
delay(4000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("HUMBA!!!");
delay(500);
lcd.clear();
lcd.setCursor(0,0);
delay(500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("HUMBA!!!");
delay(500);
lcd.clear();
lcd.setCursor(0,0);
delay(500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("HUMBA!!!");
delay(500);
}
Unsere Ziele für heute:
-> beide Programme mit einander verknüpfen
ZIEL:
#include
#include
LiquidCrystal_I2C lcd(0x27, 16, 2);
int trigger=7;
int echo=6;
long dauer=0;
long entfernung=0;
void setup()
{
Serial.begin (9600);
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);
lcd.begin();
}
void loop()
{
digitalWrite(trigger, LOW);
delay(5);
digitalWrite(trigger, HIGH);
delay(10);
digitalWrite(trigger, LOW);
dauer = pulseIn(echo, HIGH);
entfernung = (dauer/2) / 29.1;
if (entfernung >= 500 || entfernung <= 0)
{
Serial.println("Kein Messwert");
}
else
{
Serial.print(entfernung);
Serial.println(" cm");
}
delay(500);
lcd.clear();<<
lcd.setCursor(0,0);
lcd.print("Messung: ");
lcd.print(entfernung);
}