Pc Lap Counter

Logiciel de comptage
 
HomeHome  FAQFAQ  SearchSearch  RegisterRegister  MemberlistMemberlist  UsergroupsUsergroups  Log in  

Share | 
 

 Sketch with 4 lanes- Pause Button & Power control for Analogue Track

View previous topic View next topic Go down 
AuthorMessage
steve112



Number of posts : 2
Registration date : 2013-10-26

PostSubject: Sketch with 4 lanes- Pause Button & Power control for Analogue Track   9/12/2014, 22:56

Here my sketch for Arduino & PCLC..

Good Race to All  Very Happy

Steve112


// Pclapcounter & Arduino
// sketch for 4 lanes - 1 power rele - 1 PauseButton
// Autor: Steve112 - Nes Team
//
// Lanes = InputPins 2-3-4-5
// Pause Button = InputPin 8
// Porew control = OutputPin 6

int LANE1 = 2;
int LANE2 = 3;
int LANE3 = 4;
int LANE4 = 5;
int RELE = 6;
int LED = 13;
int PAUSA = 8;

 int L1Flag = 0;
 int L2Flag = 0;
 int L3Flag = 0;
 int L4Flag = 0;

long Inibit=3000;

unsigned long L1;
unsigned long L2;
unsigned long L3;
unsigned long L4;
unsigned long P1;


int val=0;
 int L1State = 0;
 int L2State = 0;
 int L3State = 0;
 int L4State = 0;
 int Pa=0;
// setup routine :
void setup() {
 //  serial communication at 9600 bits :
 Serial.begin(9600);
 // here we set input/output Pins :
 pinMode(LANE1, INPUT);
 pinMode(LANE2, INPUT);
 pinMode(LANE3, INPUT);
 pinMode(LANE4, INPUT);
 pinMode(PAUSA, INPUT);//pause button
 pinMode(LED, OUTPUT);
 pinMode(RELE, OUTPUT);//power
}


void loop() {
 
 L1State = digitalRead(LANE1);
 L2State = digitalRead(LANE2);
 L3State = digitalRead(LANE3);
 L4State = digitalRead(LANE4);
 Pa = digitalRead(PAUSA);


 if ( Serial.available() )
 {
   String b;
   b = Serial.readStringUntil('[');
   {
     String s;
//power control
     s = Serial.readStringUntil(']');
     if ( s == "PW000" ) {
       digitalWrite(LED, LOW);
       digitalWrite(RELE, LOW);
      val = 0;
     }
     if ( s == "PW001" ) {
       digitalWrite(LED, HIGH);
       digitalWrite(RELE, HIGH);
        val = 1;
     }
 }
}


  if (val == 1) {  
  // Car cross the Start/Finish line
 

 
 
 if ((L1State == 1) && ((millis()-L1)>Inibit)  && (L1Flag == 0) ){
   Serial.println("[SF01]");
   L1=millis();
   L1Flag = 1;
 };
if ((L2State == 1)&& ((millis()-L2)>Inibit)&& (L2Flag == 0)){
   Serial.println("[SF02]");
   L2=millis();
   L2Flag = 1;
 };
  if ((L3State == 1)&& ((millis()-L3)>Inibit)&& (L3Flag == 0)){
   Serial.println("[SF03]");
   L3=millis();
   L3Flag = 1;
 };
  if ((L4State == 1)&& ((millis()-L4)>Inibit)&& (L4Flag == 0)){
   Serial.println("[SF04]");
   L4=millis();
   L4Flag = 1;
 };
 
 
 
   if ((L1State == 0) &&  (L1Flag = 1) && ((millis()-L1)>Inibit)  ){
   L1Flag = 0;
       L1=millis();
 };
     if ((L2State == 0) &&  (L1Flag = 2) && ((millis()-L2)>Inibit)  ){
   L2Flag = 0;
       L2=millis();
 };
  if ((L3State == 0) &&  (L1Flag = 3) && ((millis()-L3)>Inibit)  ){
   L3Flag = 0;
       L3=millis();
 };
     if ((L4State == 0) &&  (L1Flag = 4) && ((millis()-L4)>Inibit)  ){
   L4Flag = 0;
       L4=millis();
 };
 
}

//pause/resume command
   if ((Pa == 1)&& ((millis()-P1)>900)){
  Serial.println("[BT04]");
  P1=millis();
}
}
Back to top Go down
View user profile
 
Sketch with 4 lanes- Pause Button & Power control for Analogue Track
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Dead battery, Climate control stuck on,trac light stuck off
» Sargent EC155 Power Control System problem
» Broadway Sargent control panel fault
» FAQ: How to tune the PCM? (Series II SC)
» Quick Track Button repair

Permissions in this forum:You cannot reply to topics in this forum
Pc Lap Counter :: Hardware :: Arduino-
Jump to: