kk logo

  

0 pinewood derby rennstrecke selber bauen mit Zeitmessung

M5Stack Code

from m5stack import *
from m5ui import *
from uiflow import *
import unit

setScreenColor(0xccbebe)
pbhub0 = unit.get(unit.PBHUB, (21,22))

laufl1 = None
zehntel = None
start = None
laufl2 = None
lauf = None
bahn1 = None
hell = None
bahn2 = None
sekunde = None

gms = M5Title(title="www.kreativekiste.de", x=80, fgcolor=0xf7f3f3, bgcolor=0x000000)
Bahn1 = M5TextBox(7, 36, "Zeit Bahn1", lcd.FONT_DejaVu24, 0x000000, rotate=0)
Bahn2 = M5TextBox(7, 120, "Zeit Bahn2", lcd.FONT_DejaVu24, 0x000000, rotate=0)
label0 = M5TextBox(90, 80, "0", lcd.FONT_DejaVu24, 0x000000, rotate=0)
label1 = M5TextBox(40, 80, "0", lcd.FONT_DejaVu24, 0x000000, rotate=0)
label2 = M5TextBox(90, 160, "0", lcd.FONT_DejaVu24, 0x000000, rotate=0)
label7 = M5TextBox(60, 80, ",", lcd.FONT_DejaVu24, 0x000000, rotate=0)
label3 = M5TextBox(40, 160, "0", lcd.FONT_DejaVu24, 0x000000, rotate=0)
label8 = M5TextBox(69, 160, ",", lcd.FONT_DejaVu24, 0x000000, rotate=0)
label4 = M5TextBox(228, 219, "reset", lcd.FONT_DejaVu18, 0x0321ff, rotate=0)
label9 = M5TextBox(138, 85, "Sekunden", lcd.FONT_Default, 0x000000, rotate=0)
label5 = M5TextBox(48, 224, "dimmer", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label10 = M5TextBox(138, 165, "Sekunden", lcd.FONT_Default, 0x000000, rotate=0)
label6 = M5TextBox(121, 224, "1-bis-211", lcd.FONT_Default, 0xFFFFFF, rotate=0)

from numbers import Number

def buttonA_wasPressed():
global laufl1, zehntel, start, laufl2, lauf, bahn1, hell, bahn2, sekunde
label5.show()
label6.show()
if hell >= 10:
hell = (hell if isinstance(hell, Number) else 0) + -10
label5.setText(str(hell))
pbhub0.setBrightness(0, hell)
pass
btnA.wasPressed(buttonA_wasPressed)

def buttonB_wasPressed():
global laufl1, zehntel, start, laufl2, lauf, bahn1, hell, bahn2, sekunde
label5.show()
label6.show()
if hell <= 204:
hell = (hell if isinstance(hell, Number) else 0) + 10
label5.setText(str(hell))
pbhub0.setBrightness(0, hell)
pass
btnB.wasPressed(buttonB_wasPressed)

def buttonC_wasPressed():
global laufl1, zehntel, start, laufl2, lauf, bahn1, hell, bahn2, sekunde
timerSch.stop('timer2')
timerSch.run('timer1', 200, 0x00)
pbhub0.setColor(0, 0, 30, 0xcc0000)
start = 0
lauf = 0
bahn1 = 0
bahn2 = 0
laufl1 = 1
laufl2 = 1
zehntel = 0
sekunde = 0
label5.hide()
label6.hide()
label0.setText(str(zehntel))
label1.setText(str(sekunde))
label2.setText(str(zehntel))
label3.setText(str(sekunde))
pass
btnC.wasPressed(buttonC_wasPressed)

@timerSch.event('timer1')
def ttimer1():
global laufl1, zehntel, start, laufl2, lauf, bahn1, hell, bahn2, sekunde
laufl1 = (laufl1 if isinstance(laufl1, Number) else 0) + 1
laufl2 = (laufl2 if isinstance(laufl2, Number) else 0) + 1
pass

@timerSch.event('timer2')
def ttimer2():
global laufl1, zehntel, start, laufl2, lauf, bahn1, hell, bahn2, sekunde
zehntel = (zehntel if isinstance(zehntel, Number) else 0) + 2
pass

start = 0
lauf = 0
bahn1 = 0
bahn2 = 0
laufl1 = 1
laufl2 = 1
zehntel = 0
sekunde = 0
hell = 41
label5.hide()
label6.hide()
pbhub0.setRgbNum(0, 30)
pbhub0.setColor(0, 0, 30, 0xcc0000)
timerSch.run('timer1', 150, 0x00)
while True:
if not (pbhub0.digitalRead(1, 0)):
timerSch.stop('timer1')
start = 1
timerSch.run('timer2', 10, 0x00)
pbhub0.setColor(0, 0, 30, 0x000099)
if start == 1:
if zehntel >= 99:
zehntel = 0
sekunde = (sekunde if isinstance(sekunde, Number) else 0) + 1
if bahn1 == 0:
label0.setText(str(zehntel))
label1.setText(str(sekunde))
if bahn2 == 0:
label2.setText(str(zehntel))
label3.setText(str(sekunde))
if not (pbhub0.digitalRead(4, 0)):
bahn1 = 1
if bahn1 == 1 and bahn2 == 0:
pbhub0.setColor(0, 0, 15, 0x009900)
pbhub0.setColor(0, 15, 30, 0xcc0000)
if not (pbhub0.digitalRead(5, 0)):
bahn2 = 1
if bahn1 == 0 and bahn2 == 1:
pbhub0.setColor(0, 0, 15, 0xff0000)
pbhub0.setColor(0, 15, 30, 0x009900)
else:
if lauf == 0:
pbhub0.setColor(0, 0, laufl1, 0x009900)
pbhub0.setColor(0, 15, laufl2, 0x009900)
else:
pbhub0.setColor(0, 0, laufl1, 0xcc0000)
pbhub0.setColor(0, 15, laufl2, 0xcc0000)
if laufl1 == 16 and lauf == 0:
laufl1 = 1
laufl2 = 1
lauf = 1
if laufl1 == 16 and lauf == 1:
laufl1 = 1
laufl2 = 1
lauf = 0
wait_ms(2)

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

 

 

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 );
}

King of my heart

Let the King of my heart
Be the mountain where I run
The fountain I drink from
Oh, He is my song

Ronnie

schwäbischer tüftler und bastler, kraftsportler, ADHS power, 43 Jahre, 1 Frau, 5 Kinder und 1003 Ideen. 

ronnie berzins at mee