From 8b761685ccb76ad75e2bbc2bac148208598e36ae Mon Sep 17 00:00:00 2001 From: Luca Borsari Date: Thu, 16 Jul 2020 13:49:31 +0200 Subject: [PATCH] ver 0.9.c --- changelog.txt | 19 +++++++++ open-led-race/olr-controller.h | 5 +-- open-led-race/olr-lib.c | 7 ++-- open-led-race/open-led-race.ino | 69 +++++++++++++++++++++++++-------- 4 files changed, 76 insertions(+), 24 deletions(-) create mode 100644 changelog.txt diff --git a/changelog.txt b/changelog.txt new file mode 100644 index 0000000..ecd53c5 --- /dev/null +++ b/changelog.txt @@ -0,0 +1,19 @@ +Revisions history +----------------- + + * 2020-07-16: Ver 0.9.c - Luca + - Changes in [I/O Pin]<>[Car Color] association to match + the desired Phisical Buttons Layout (Quick Start Guide) + - Box/Pitlane + - Entry/exit point marked to help put in place led strip (circuit shape) + - Coin "Boost" scaled up to make "catch it" worth (almost always win the race) + - Minor bugfix: + - box_init(), box_isactive() use wrong var "rampactive" + + * 2020-07-16: Ver 0.9.b - Gerardo + - Sound FX added + + * 2019-10-10 - Ver 0.9.a + -First public Version by Angel Maldonado (Maker Faire Roma 2019) + + diff --git a/open-led-race/olr-controller.h b/open-led-race/olr-controller.h index 301f5d5..05d4399 100644 --- a/open-led-race/olr-controller.h +++ b/open-led-race/olr-controller.h @@ -12,11 +12,10 @@ extern "C"{ #include - #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 +#define DIG_CONTROL_3 A3 // switch player 3 to PIN and GND +#define DIG_CONTROL_4 A1 // switch player 4 to PIN and GND #define PIN_VCC_ADC1 6 #define PIN_VCC_ADC2 7 diff --git a/open-led-race/olr-lib.c b/open-led-race/olr-lib.c index b98a2f5..096c5b9 100644 --- a/open-led-race/olr-lib.c +++ b/open-led-race/olr-lib.c @@ -51,7 +51,7 @@ void process_aux_track( track_t* tck, car_t* car ){ if ( (int)car->dist_aux == tck->ledcoin && car->speed <= controller_getAccel() ) { - car->speed = controller_getAccel ()*10; + car->speed = controller_getAccel ()*50; tck->ledcoin = COIN_RESET; }; @@ -98,11 +98,11 @@ void car_resetPosition( car_t* car) { } void box_init( track_t* tck ) { - tck->rampactive = true; + tck->boxactive = true; } bool box_isactive( track_t* tck ) { - return tck->rampactive; + return tck->boxactive; } int box_configure( track_t* tck, int init_box ) { @@ -122,4 +122,3 @@ int ramp_configure( track_t* tck, int center, int high ) { ramp->high = high; return 0; } - diff --git a/open-led-race/open-led-race.ino b/open-led-race/open-led-race.ino index a2a7822..0478124 100644 --- a/open-led-race/open-led-race.ino +++ b/open-led-race/open-led-race.ino @@ -15,12 +15,30 @@ the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - by gbarbarov@singulardevices.com for Arduino day Seville 2019 - Code made dirty and fast, next improvements in: - https://github.com/gbarbarov/led-race + First public version by: + Angel Maldonado (https://gitlab.com/angeljmc) + + Basen on original idea and 2 players code by: + gbarbarov@singulardevices.com for Arduino day Seville 2019 + https://github.com/gbarbarov/led-race + + + Public Repository for this code: + https://gitlab.com/open-led-race/olr-arduino + + + 2020/07/16 - Ver 0.9.c + --see changelog.txt + + + */ +char const version[] = "0.9.c"; + + + #include #include #include "AsyncSerialLib.h" @@ -34,11 +52,12 @@ #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) +#define COLOR3 track.Color(0,0,255) +#define COLOR4 track.Color(255,255,255) #define COLOR_RAMP track.Color(64,0,64) #define COLOR_COIN track.Color(0,255,255) +#define COLOR_BOXMARKS track.Color(64,64,0) #define LED_SEMAPHORE 12 @@ -130,7 +149,6 @@ int win_music[] = { //int TBEEP=3; -char const version[] = "0.9"; char tracksID[ NUM_TRACKS ][2] ={"U","M","B","I","O"}; /* ----------- Function prototypes ------------------- */ @@ -150,6 +168,7 @@ AsyncSerial asyncSerial(data, dataLength, Adafruit_NeoPixel track = Adafruit_NeoPixel( MAXLED, PIN_LED, NEO_GRB + NEO_KHZ800 ); +char tmpmsg [20]; void setup() { @@ -157,41 +176,45 @@ void setup() { randomSeed( analogRead(A6) + analogRead(A7) ); controller_setup( ); param_load( &tck.cfg ); - - car_init( &cars[0], &switchs[0], COLOR1 ); + controller_init( &switchs[0], DIGITAL_MODE, DIG_CONTROL_1 ); - car_init( &cars[1], &switchs[1], COLOR2 ); + car_init( &cars[0], &switchs[0], COLOR1 ); controller_init( &switchs[1], DIGITAL_MODE, DIG_CONTROL_2 ); + car_init( &cars[1], &switchs[1], COLOR2 ); + race.numcars = 2; if( controller_isActive( DIG_CONTROL_3 )) { - car_init( &cars[2], &switchs[2], COLOR3 ); controller_init( &switchs[2], DIGITAL_MODE, DIG_CONTROL_3 ); + car_init( &cars[2], &switchs[2], COLOR3 ); ++race.numcars; } if( controller_isActive( DIG_CONTROL_4 )) { - car_init( &cars[3], &switchs[3], COLOR4 ); controller_init( &switchs[3], DIGITAL_MODE, DIG_CONTROL_4 ); + car_init( &cars[3], &switchs[3], COLOR4 ); ++race.numcars; } track.begin(); + // Check Box before Physic/Sound to allow user to have Box and Physics with no sound + if ( digitalRead( DIG_CONTROL_2 ) == 0 ) { //push switch 2 on reset for activate boxes (pit lane) + box_init( &tck ); + box_configure( &tck, 240 ); + } + if ( digitalRead( DIG_CONTROL_1 ) == 0 ) { //push switch 1 on reset for activate physics ramp_init( &tck ); draw_ramp( &tck ); track.show(); - delay(1000); + delay(2000); if ( digitalRead( DIG_CONTROL_1 ) == 0 ) { //retain push switch on reset for activate FX sound SMOTOR=1; tone(PIN_AUDIO,100);} } - if ( digitalRead( DIG_CONTROL_2 ) == 0 ) { //push switch 2 on reset for activate boxes - box_init( &tck ); - box_configure( &tck, 240 ); - } + race.cfg.startline = true; race.cfg.nlap = 5; @@ -227,6 +250,9 @@ void loop() { if( ramp_isactive( &tck ) ){ draw_ramp( &tck ); } + if( box_isactive( &tck ) ) { + draw_box_entrypoint( &tck ); + } track.show(); delay( 2000 ); @@ -257,7 +283,7 @@ void loop() { if( ramp_isactive( &tck ) ) draw_ramp( &tck ); - + for( int i = 0; i < race.numcars; ++i ) { run_racecycle( &cars[i], i ); if( cars[i].st == CAR_FINISH ) { @@ -469,6 +495,15 @@ void draw_ramp( track_t* tck ) { } +void draw_box_entrypoint( track_t* tck ) { + struct cfgtrack const* cfg = &tck->cfg.track; + track.setPixelColor(cfg->init_aux ,COLOR_BOXMARKS ); // Pit lane exit (race start) + track.setPixelColor(cfg->init_aux - cfg->nled_aux + 1 ,COLOR_BOXMARKS ); // Pit lane Entrance +} + + + + void printdebug( const char * msg, int errlevel ) { char header[4];