From 3372cade520343032bd78f23bd75a0064af1b21f Mon Sep 17 00:00:00 2001 From: Angel Maldonado Date: Sun, 13 Oct 2019 10:12:44 +0200 Subject: [PATCH] Effect of ramp and box configurable with the controls after switching on --- lib/Openledrace-lib/olr-controller.h | 4 ++-- lib/Openledrace-lib/olr-lib.c | 8 +++++++- lib/Openledrace-lib/olr-lib.h | 2 ++ lib/Openledrace-lib/olr-param.h | 1 + src/open-led-race.ino | 19 ++++++++++++++++--- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/Openledrace-lib/olr-controller.h b/lib/Openledrace-lib/olr-controller.h index 941a63a..f8ed085 100644 --- a/lib/Openledrace-lib/olr-controller.h +++ b/lib/Openledrace-lib/olr-controller.h @@ -13,8 +13,8 @@ extern "C"{ -#define DIG_CONTROL_1 A0 // switch player 1 to PIN and GND -#define DIG_CONTROL_2 A2 // switch player 2 to PIN and GND +#define DIG_CONTROL_1 A2 // switch player 1 to PIN and GND +#define DIG_CONTROL_2 A0 // switch player 2 to PIN and GND #define DIG_CONTROL_3 A1 // switch player 3 to PIN and GND #define DIG_CONTROL_4 A3 // switch player 4 to PIN and GND diff --git a/lib/Openledrace-lib/olr-lib.c b/lib/Openledrace-lib/olr-lib.c index 886a750..37d9e45 100644 --- a/lib/Openledrace-lib/olr-lib.c +++ b/lib/Openledrace-lib/olr-lib.c @@ -82,7 +82,7 @@ void init_ramp( track_t* tck ) { } void set_ramp( track_t* tck ) { - struct cfgramp const* r = &tck->cfg.ramp; + struct cfgramp* r = &tck->cfg.ramp; for( int i=0; i<(r->center - r->init); i++ ) tck->gmap[r->init+i] = 127-i*((float)r->high/(r->center - r->init)); @@ -90,6 +90,12 @@ void set_ramp( track_t* tck ) { for( int i=0; i<(r->end - r->center); i++ ) tck->gmap[r->center+i+1] = 127+r->high-i*((float)r->high/(r->end-r->center)); + + r->enabled = true; +} + +bool ramp_isactive( track_t* tck ) { + return tck->cfg.ramp.enabled; } diff --git a/lib/Openledrace-lib/olr-lib.h b/lib/Openledrace-lib/olr-lib.h index 4bbb2e9..efc4049 100644 --- a/lib/Openledrace-lib/olr-lib.h +++ b/lib/Openledrace-lib/olr-lib.h @@ -65,6 +65,8 @@ void init_ramp( track_t* tck ); void set_ramp( track_t* tck ); +bool ramp_isactive( track_t* tck ); + void init_car( car_t* car, controller_t* ct, uint32_t color ); void update_track( track_t* tck, car_t* car ); diff --git a/lib/Openledrace-lib/olr-param.h b/lib/Openledrace-lib/olr-param.h index 8576d86..cde1d92 100644 --- a/lib/Openledrace-lib/olr-param.h +++ b/lib/Openledrace-lib/olr-param.h @@ -35,6 +35,7 @@ struct cfgramp { int center; int end; int high; + bool enabled; }; struct brdinfo { diff --git a/src/open-led-race.ino b/src/open-led-race.ino index 7a6c1f2..08747a6 100644 --- a/src/open-led-race.ino +++ b/src/open-led-race.ino @@ -32,14 +32,14 @@ #define EOL '\n' -#define COLOR1 track.Color(0,255,0) -#define COLOR2 track.Color(255,0,0) +#define COLOR1 track.Color(255,0,0) +#define COLOR2 track.Color(0,255,0) #define COLOR3 track.Color(255,255,255) #define COLOR4 track.Color(0,0,255) enum{ - MAX_CARS = 4, + MAX_CARS = 2, }; @@ -176,6 +176,16 @@ void setup() { track.begin(); + if ( digitalRead( DIG_CONTROL_1 ) == 0 ) { //push switch 1 on reset for activate physic + set_ramp( &tck ); + draw_ramp( &tck ); + track.show(); + } + + if ( digitalRead( DIG_CONTROL_2 ) == 0 ) { //push switch 2 on reset for activate box + track_configure( &tck, 240 ); + } + race.cfg.startline = true; race.cfg.nlap = 5; race.cfg.nrepeat = 1; @@ -225,6 +235,9 @@ void loop() { tck.ledtime = millis() + random(2000,7000); } + if( ramp_isactive( &tck ) ) + draw_ramp( &tck ); + if( tck.ledcoin > 0 ) draw_coin( &tck ); else if( millis() > tck.ledtime )