stealcat
Published

Reaction Training Machine

Train user reaction timing.

AdvancedProtip960
Reaction Training Machine

Things used in this project

Story

Read more

Schematics

training reaction machine

Code

training reaction machine code

Arduino
this is the code of our machine
byte seven_seg_digits[10][7] = { { 1,1,1,1,1,1,0 },  // = 0 //
                                 { 0,1,1,0,0,0,0 },  // = 1
                                 { 1,1,0,1,1,0,1 },  // = 2
                                 { 1,1,1,1,0,0,1 },  // = 3
                                 { 0,1,1,0,0,1,1 },  // = 4
                                 { 1,0,1,1,0,1,1 },  // = 5
                                 { 1,0,1,1,1,1,1 },  // = 6
                                 { 1,1,1,0,0,0,0 },  // = 7
                                 { 1,1,1,1,1,1,1 },  // = 8
                                 { 1,1,1,0,0,1,1 }   // = 9
                             };
//.................................................................//
int ledPind = 13; //LED
int ledPinr = 12;
int ledPinu = 11;
int ledPinl = 10;
long ran;
//.................................................................//
int analogInPin = 0;//
int sensorValue = 0;
int ButtonPin = 2;

//.......................................................//
int t = 0;
int score = 0; //
int tt = 800; //
int tc = 0;  //time change tt

void setup() {
  pinMode(2, OUTPUT);  //
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  digitalWrite(9, 0);  

  pinMode(ledPind, OUTPUT); //LED
  pinMode(ledPinr, OUTPUT);
  pinMode(ledPinu, OUTPUT); 
  pinMode(ledPinl, OUTPUT);

  Serial.begin(9600);     //
  pinMode(ButtonPin, INPUT);

}

//  
void sevenSegWrite(byte digit) {
  byte pin = 2;
  for (byte seg = 0; seg < 7; ++seg) {
    digitalWrite(pin, seven_seg_digits[digit][seg]);
    ++pin;
  }
}


void loop() {
 ran = random(4);  //LED
 sevenSegWrite(score); 
if(ran==0){                                          //down
  while(t<tt){
digitalWrite(ledPind, HIGH);                        //led
digitalWrite(ledPinr, LOW); 
digitalWrite(ledPinu, LOW); 
digitalWrite(ledPinl, LOW);  
if(analogRead(0)<600 && analogRead(0)>450 && analogRead(1)<600 && analogRead(1)>450){   
 if(t==tt-1){                                             // 
  if(score==0){score=0; tc=0;}    //1/1000
  else{score=score-1; tc=1;}}
t=t+1;
delay(1);
}
else if(analogRead(0)>600 || analogRead(0)<450 || analogRead(1)>600 || analogRead(1)<450){ 
 if(analogRead(1)<450){  //+                    //
  if(score==9){score=9; tc=0;}
  else{score=score+1; tc=2;}
  sevenSegWrite(score);
  delay(tt-t);
  t=tt;
 } 
 else{                  //-
  if(score==0){score=0; tc=0;}
  else{score=score-1; tc=1;}
  sevenSegWrite(score);
  delay(tt-t);
  t=tt;
 } 
}
}
digitalWrite(ledPind, LOW); // 
t=0;
if(tc==1){tt=tt+70;}
else if(tc==2){tt=tt-70;}
delay(50);
}  

if(ran==1){                                       //right(  )
 while(t<tt){
digitalWrite(ledPind, LOW);
digitalWrite(ledPinr, HIGH); 
digitalWrite(ledPinu, LOW); 
digitalWrite(ledPinl, LOW);  
if(analogRead(0)<600 && analogRead(0)>450 && analogRead(1)<600 && analogRead(1)>450){
 if(t==tt-1){
  if(score==0){score=0; tc=0;}
  else{score=score-1; tc=1;}}
t=t+1;
delay(1);
}
else if(analogRead(0)>600 || analogRead(0)<450 || analogRead(1)>600 || analogRead(1)<450){
 if(analogRead(0)>600){
  if(score==9){score=9; tc=0;}
  else{score=score+1; tc=2;}
  sevenSegWrite(score);
  delay(tt-t);
  t=tt;
 } 
 else{
  if(score==0){score=0; tc=0;}
  else{score=score-1; tc=1;}
  sevenSegWrite(score);
  delay(tt-t);
  t=tt;
 } 
}
}
digitalWrite(ledPinr, LOW);
t=0;
if(tc==1){tt=tt+70;}
else if(tc==2){tt=tt-70;}
delay(50);
}

if(ran==2){                                                                        //up
 while(t<tt){
digitalWrite(ledPind, LOW);
digitalWrite(ledPinr, LOW); 
digitalWrite(ledPinu, HIGH); 
digitalWrite(ledPinl, LOW);  
if(analogRead(0)<600 && analogRead(0)>450 && analogRead(1)<600 && analogRead(1)>450){
 if(t==tt-1){
  if(score==0){score=0; tc=0;}
  else{score=score-1; tc=1;}}
t=t+1;
delay(1);
}
else if(analogRead(0)>600 || analogRead(0)<450 || analogRead(1)>600 || analogRead(1)<450){
 if(analogRead(1)>600){
  if(score==9){score=9; tc=0;}
  else{score=score+1; tc=2;}
  sevenSegWrite(score);
  delay(tt-t);
  t=tt;
 } 
 else{
  if(score==0){score=0; tc=0;}
  else{score=score-1; tc=1;}
  sevenSegWrite(score);
  delay(tt-t);
  t=tt;
 } 
}
}
digitalWrite(ledPinu, LOW);
t=0;
if(tc==1){tt=tt+70;}
else if(tc==2){tt=tt-70;}
delay(50);
}

if(ran==3){                                                        //left              
 while(t<tt){
digitalWrite(ledPind, LOW);
digitalWrite(ledPinr, LOW); 
digitalWrite(ledPinu, LOW); 
digitalWrite(ledPinl, HIGH);  
if(analogRead(0)<600 && analogRead(0)>450 && analogRead(1)<600 && analogRead(1)>450){
 if(t==tt-1){
  if(score==0){score=0; tc=0;}
  else{score=score-1; tc=1;}}
t=t+1;
delay(1);
}
else if(analogRead(0)>600 || analogRead(0)<450 || analogRead(1)>600 || analogRead(1)<450){
 if(analogRead(0)<450){
  if(score==9){score=9; tc=0;}
  else{score=score+1; tc=2;}
  sevenSegWrite(score);
  delay(tt-t);
  t=tt;
 } 
 else{
  if(score==0){score=0; tc=0;}
  else{score=score-1; tc=1;}
  sevenSegWrite(score);
  delay(tt-t);
  t=tt;
 } 
}
}
digitalWrite(ledPinl, LOW);
t=0;
if(tc==1){tt=tt+70;}
else if(tc==2){tt=tt-70;}
delay(50);
}

 
}

Credits

stealcat

stealcat

0 projects • 0 followers

Comments

Add projectSign up / Login