Der Code gehört zu der Schaltung in diesem Youtube Video: https://youtu.be/JmsHbYGa2oQ
Schaltplan für die Arduino Formel 1 Rennstrecke:
Die Ardublock Datei Version "duinoEDU, experimentell, 0. 70.04" gibt es hier zum Download . ZIP Datei.
Arduino Code:
--------------------------------------------------------------------------------------------------------------
#include <Servo.h>
#include <codeCache.h>
#include <Duinoedu_Time.h>
boolean __ardublockDigitalRead(int pinNumber)
{
pinMode(pinNumber, INPUT);
return digitalRead(pinNumber);
}
int a1;
Servo servo_pin_7;
char Char = ' ' ;
bool spieler1= false ;
bool spieler2= false ;
Duinoedu_Time monTemps;
float zeit1 = 0.0 ;
float zeit2 = 0.0 ;
void start();
#include <Wire.h>;
#include <LiquidCrystal_I2C.h>;
LiquidCrystal_I2C lcd(0x27,20,4);
;
void setup()
{
pinMode( 11 , OUTPUT);
pinMode( 6 , OUTPUT);
pinMode( 8 , OUTPUT);
pinMode( 9 , OUTPUT);
pinMode( 10 , OUTPUT);
servo_pin_7.attach(7);
lcd.init();
;
lcd.backlight();
;
start();
}
void loop()
{
if (!( __ardublockDigitalRead(D4) ))
{
digitalWrite(8 , LOW);
digitalWrite(10 , LOW);
for ( a1=1; a1<= ( 3 ); ++a1 )
{
delay( 500 );
digitalWrite(8 , HIGH);
digitalWrite(10 , HIGH);
delay( 500 );
digitalWrite(8 , LOW);
digitalWrite(10 , LOW);
}
digitalWrite(9 , HIGH);
digitalWrite(11 , HIGH);
servo_pin_7.write( 120 );
digitalWrite(6 , HIGH);
Char = 'A';
lcd.clear();
spieler1 = LOW ;
spieler2 = LOW ;
monTemps.resetDeltat();
lcd.setCursor(0,0);
;
lcd.print("CAR right");
;
lcd.setCursor(0,1);
;
lcd.print("CAR left");
;
while ( ( ( String(Char) ) == ( String("A") ) ) )
{
lcd.setCursor(11,0);
;
lcd.print(zeit1);
;
lcd.setCursor(11,1);
;
lcd.print(zeit2);
;
if (!( __ardublockDigitalRead(D2) ))
{
if (( ( ( spieler1 ) == ( LOW ) ) && !( ( ( spieler2 ) == ( HIGH ) ) ) ))
{
lcd.setCursor(0,2);
;
lcd.print("WINNER right");
;
lcd.setCursor(0,3);
;
lcd.print("LOSER left");
;
digitalWrite(8 , HIGH);
digitalWrite(9 , LOW);
digitalWrite(10 , LOW);
digitalWrite(11 , HIGH);
digitalWrite(6 , LOW);
}
spieler1 = HIGH ;
}
if (!( __ardublockDigitalRead(D3) ))
{
if (( ( ( spieler2 ) == ( LOW ) ) && !( ( ( spieler1 ) == ( HIGH ) ) ) ))
{
lcd.setCursor(0,2);
;
lcd.print("WINNER left");
;
lcd.setCursor(0,3);
;
lcd.print("LOSER right");
;
digitalWrite(8 , LOW);
digitalWrite(9 , HIGH);
digitalWrite(10 , HIGH);
digitalWrite(11 , LOW);
digitalWrite(6 , LOW);
}
spieler2 = HIGH ;
}
if (( ( spieler1 ) == ( LOW ) ))
{
zeit1 = ( monTemps.Deltat() * 0.001 ) ;
}
if (( ( spieler2 ) == ( LOW ) ))
{
zeit2 = ( monTemps.Deltat() * 0.001 ) ;
}
if (( ( ( spieler1 ) == ( HIGH ) ) && ( ( spieler2 ) == ( HIGH ) ) ))
{
Char = 'B';
}
}
}
while ( ( ( String(Char) ) == ( String("B") ) ) )
{
if (!( __ardublockDigitalRead(D4) ))
{
lcd.clear();
Char = 'A';
start();
}
}
}
void start()
{
lcd.setCursor(0,0);
;
lcd.print("CAR right");
;
lcd.setCursor(0,1);
;
lcd.print("CAR left");
;
digitalWrite(6 , LOW);
digitalWrite(8 , HIGH);
digitalWrite(10 , HIGH);
digitalWrite(9 , LOW);
digitalWrite(11 , LOW);
Char = 'A';
servo_pin_7.write( 0 );
monTemps.resetDeltat();
zeit1 = 0.0 ;
zeit2 = 0.0 ;
lcd.setCursor(11,0);
;
lcd.print(zeit1);
;
lcd.setCursor(11,1);
;
lcd.print(zeit2);
;
delay( 700 );
}