Go Down

Topic: Arduino-DVD-KIT (Read 3323 times) previous topic - next topic

tolle

Perhaps someone knows the DVD-Kit for the arduino.

I am working at following problem:

I wish to integrate one of the IR buttons to adjust the motor speed  
going up and down automatically.
After a short delay the direction of the rotation should be changed
and so on in a loop, till pressing another button.

I know this must be a simple loop.
But i  cannot  stop the loop when pressing another button.

::)Who knows ?


Here the original program:


#define motor1Pin 4  //[ch25509]L293D [ch33455][ch29255]1A[ch25509][ch33050]
#define motor2Pin 5  //[ch25509]L293D [ch33455][ch29255]2A[ch25509][ch33050]
#define enablePin 11  //PWM[ch25509][ch33050]11[ch25509]EN[ch25509][ch33050]
#define IR_IN  8  //[ch32418][ch22806][ch25509][ch25910]
#define LED_g  12  //[ch32511]led
#define LED_r  13  //[ch32418]led

//[ch35774][ch32622][ch25511][ch21046][ch21508][ch27573][ch30340][ch25968][ch23383]IO[ch33050]
 int a = 1;
 int b = 2;
 int c = 3;
 int d = 6;
 int e = 7;
 int f = 9;
 int g = 10;

//[ch32418][ch22806][ch36965][ch25511][ch37197][ch32622]
 int Pulse_Width=0;//[ch23384][ch20648][ch33033][ch23485]
 int ir_code=0x00;// [ch29992][ch25143][ch32534][ch30721][ch20540]
 char  adrL_code=0x00;//[ch21629][ch20196][ch30721]
 char  adrH_code=0x00;//[ch21629][ch20196][ch30721][ch21453][ch30721]
 
//[ch30005][ch26426][ch21442][ch25968][ch25511][ch21046]
 boolean turn = true ;
 
//LED[ch28783][ch29366][ch24577][ch21442][ch25968]
 boolean ledSt = true ;
 
void timer1_init(void)//[ch23450][ch26102][ch22120][ch21021][ch22987][ch21270][ch20989][ch25968]
{
 TCCR1A = 0X00;
 TCCR1B = 0X05;//[ch32473][ch23450][ch26102][ch22120][ch26102][ch38047][ch28304]  
 TCCR1C = 0X00;
 TCNT1 = 0X00;
 TIMSK1 = 0X00;      //[ch31105][ch27490][ch23450][ch26102][ch22120][ch28322][ch20986][ch20013][ch26029]
}

//[ch26174][ch31034][ch25968][ch23383]0  ,  11111100
void digital_0(void)
{
 digitalWrite(g,LOW);//[ch29060][ch28781]g[ch27573]
 digitalWrite(a,HIGH);
 digitalWrite(b,HIGH);
 digitalWrite(c,HIGH);
 digitalWrite(d,HIGH);
 digitalWrite(e,HIGH);
 digitalWrite(f,HIGH);
}
//[ch26174][ch31034][ch25968][ch23383]1  , 01100000
void digital_1(void)
{
 digitalWrite(a,LOW);
 digitalWrite(d,LOW);
 digitalWrite(e,LOW);
 digitalWrite(f,LOW);
 digitalWrite(g,LOW);//[ch29060][ch28781]g[ch27573]
 digitalWrite(b,HIGH);
 digitalWrite(c,HIGH);
}
//[ch26174][ch31034][ch25968][ch23383]2
void digital_2(void)
{
 digitalWrite(f,LOW);
 digitalWrite(c,LOW);
 digitalWrite(a,HIGH);
 digitalWrite(b,HIGH);
 digitalWrite(d,HIGH);
 digitalWrite(e,HIGH);
 digitalWrite(g,HIGH);
}
//[ch26174][ch31034][ch25968][ch23383]3 22
void digital_3(void)
{
 digitalWrite(e,LOW);
 digitalWrite(f,LOW);
 digitalWrite(a,HIGH);
 digitalWrite(b,HIGH);
 digitalWrite(c,HIGH);
 digitalWrite(d,HIGH);
 digitalWrite(g,HIGH);
}
//[ch26174][ch31034][ch25968][ch23383]4
void digital_4(void)
{
 digitalWrite(a,LOW);
 digitalWrite(d,LOW);
 digitalWrite(e,LOW);
 digitalWrite(b,HIGH);
 digitalWrite(c,HIGH);
 digitalWrite(f,HIGH);
 digitalWrite(g,HIGH);  
}
//[ch26174][ch31034][ch25968][ch23383]5
void digital_5(void)
{
 digitalWrite(b,LOW);
 digitalWrite(e,LOW);
 digitalWrite(a,HIGH);
 digitalWrite(c,HIGH);
 digitalWrite(d,HIGH);
 digitalWrite(f,HIGH);
 digitalWrite(g,HIGH);
}
//[ch26174][ch31034][ch25968][ch23383]6
void digital_6(void)
{
 digitalWrite(b,LOW);
 digitalWrite(a,HIGH);
 digitalWrite(c,HIGH);
 digitalWrite(d,HIGH);
 digitalWrite(e,HIGH);
 digitalWrite(f,HIGH);
 digitalWrite(g,HIGH);
}
//[ch26174][ch31034][ch25968][ch23383]7
void digital_7(void)
{
 digitalWrite(d,LOW);
 digitalWrite(e,LOW);
 digitalWrite(f,LOW);
 digitalWrite(g,LOW);
 digitalWrite(a,HIGH);
 digitalWrite(b,HIGH);
 digitalWrite(c,HIGH);
}
//[ch26174][ch31034][ch25968][ch23383]8
void digital_8(void)
{
 digitalWrite(a,HIGH);
 digitalWrite(b,HIGH);
 digitalWrite(c,HIGH);
 digitalWrite(d,HIGH);
 digitalWrite(e,HIGH);
 digitalWrite(f,HIGH);
 digitalWrite(g,HIGH);
}
//[ch26174][ch31034][ch25968][ch23383]9
void digital_9(void)
{
 digitalWrite(e,LOW);
 digitalWrite(a,HIGH);
 digitalWrite(b,HIGH);
 digitalWrite(c,HIGH);
 digitalWrite(d,HIGH);
 digitalWrite(f,HIGH);
 digitalWrite(g,HIGH);
}
void motor_turn(void) //[ch25511][ch21046][ch39532][ch36798][ch36716][ch21521]
{
 if(turn)
 {
   digitalWrite(motor1Pin, HIGH);
   digitalWrite(motor2Pin, LOW);
 }
 else
 {
   digitalWrite(motor2Pin, HIGH);
   digitalWrite(motor1Pin, LOW);    
 }
}

//[ch26174][ch31034]----------------------------
void remote_deal(void)//[ch25191][ch34892][ch35793][ch30721][ch32467][ch26524][ch20989][ch25968]
{
 switch (adrL_code) {
   case 69:
     analogWrite(enablePin, 0);//[ch20572][ch27490][ch24037][ch20316]
     break;
   case 13:
     turn  = !turn ;      //[ch20999][ch25442][ch30005][ch26426][ch29366][ch24577][ch65292] [ch30005][ch26426][ch21453][ch36716]
     ledSt = !ledSt ;    //[ch20999][ch25442][ch23567][ch28783][ch29366][ch24577]
     break;
   case 22:
     digital_0();//[ch26174][ch31034][ch25968][ch23383]0
     motor_turn();
     analogWrite(enablePin, 190); //[ch20197]PWM [ch26041][ch24335][ch65292][ch35774][ch23450][ch39532][ch36798][ch30340][ch36895][ch24230]
     break;
   case 12:
     digital_1();
     motor_turn();
     analogWrite(enablePin, 160); //[ch20197]PWM [ch26041][ch24335][ch65292][ch35774][ch23450][ch39532][ch36798][ch30340][ch36895][ch24230]
     break;
   case 24:
     digital_2();
     motor_turn();
     analogWrite(enablePin, 130); //[ch20197]PWM [ch26041][ch24335][ch65292][ch35774][ch23450][ch39532][ch36798][ch30340][ch36895][ch24230]
     break;
   case 121:
     digital_3();
     motor_turn();
     analogWrite(enablePin, 120); //[ch20197]PWM [ch26041][ch24335][ch65292][ch35774][ch23450][ch39532][ch36798][ch30340][ch36895][ch24230]
     break;
   case 8:
     digital_4();
     analogWrite(enablePin, 100); //[ch20197]PWM [ch26041][ch24335][ch65292][ch35774][ch23450][ch39532][ch36798][ch30340][ch36895][ch24230]
     break;
   case 28:
     digital_5();
     motor_turn();
     analogWrite(enablePin, 90); //[ch20197]PWM [ch26041][ch24335][ch65292][ch35774][ch23450][ch39532][ch36798][ch30340][ch36895][ch24230]
     break;
   case 90:
     digital_6();
     motor_turn();
     analogWrite(enablePin, 60); //[ch20197]PWM [ch26041][ch24335][ch65292][ch35774][ch23450][ch39532][ch36798][ch30340][ch36895][ch24230]
     break;
   case 66:
     digital_7();
     motor_turn();
     analogWrite(enablePin, 40); //[ch20197]PWM [ch26041][ch24335][ch65292][ch35774][ch23450][ch39532][ch36798][ch30340][ch36895][ch24230]
     break;
  case 82:
     digital_8();
     motor_turn();
     analogWrite(enablePin, 20); //[ch20197]PWM [ch26041][ch24335][ch65292][ch35774][ch23450][ch39532][ch36798][ch30340][ch36895][ch24230]
     break;
  case 74:
     digital_9();
     motor_turn();
     analogWrite(enablePin, 10); //[ch20197]PWM [ch26041][ch24335][ch65292][ch35774][ch23450][ch39532][ch36798][ch30340][ch36895][ch24230]
     break;  
   default: return;
 }
}

char logic_value()//[ch21028][ch26029][ch36923][ch36753][ch20540]"0"[ch21644]"1"[ch23376][ch20989][ch25968]
{
 TCNT1 = 0X00;
 while(!(digitalRead(8))); //[ch20302][ch31561][ch24453]
 Pulse_Width=TCNT1;
 TCNT1=0;
 if(Pulse_Width>=7&&Pulse_Width<=10)//[ch20302][ch30005][ch24179]560us
 {
   while(digitalRead(8));//[ch26159][ch39640][ch23601][ch31561][ch24453]
   Pulse_Width=TCNT1;
   TCNT1=0;
   if(Pulse_Width>=7&&Pulse_Width<=10)//[ch25509][ch30528][ch39640][ch30005][ch24179]560us
     return 0;
   else if(Pulse_Width>=25&&Pulse_Width<=27) //[ch25509][ch30528][ch39640][ch30005][ch24179]1.7ms
     return 1;
 }
 return -1;
}
void pulse_deal()//[ch25509][ch25910][ch22320][ch22336][ch30721][ch21644][ch21629][ch20196][ch30721][ch33033][ch20914][ch20989][ch25968]
{
 int i;
 int j;
 ir_code=0x00;// [ch28165][ch38646]
 adrL_code=0x00;// [ch28165][ch38646]
 adrH_code=0x00;// [ch28165][ch38646]

 //[ch35299][ch26512][ch36965][ch25511][ch22120][ch32534][ch30721][ch20013][ch30340][ch29992][ch25143][ch32534][ch30721][ch20540]  
 for(i = 0 ; i < 16; i++)
 {
   if(logic_value() == 1) //[ch26159]1
       ir_code |= (1<<i);//[ch20445][ch23384][ch38190][ch20540]
 }
 //[ch35299][ch26512][ch36965][ch25511][ch22120][ch32534][ch30721][ch20013][ch30340][ch21629][ch20196][ch30721]
 for(i = 0 ; i < 8; i++)
 {
   if(logic_value() == 1) //[ch26159]1
     adrL_code |= (1<<i);//[ch20445][ch23384][ch38190][ch20540]
 }
 //[ch35299][ch26512][ch36965][ch25511][ch22120][ch32534][ch30721][ch20013][ch30340][ch21629][ch20196][ch30721][ch21453][ch30721]
 for(j = 0 ; j < 8; j++)
 {
   if(logic_value() == 1) //[ch26159]1
       adrH_code |= (1<<j);//[ch20445][ch23384][ch38190][ch20540]
 }
}
void remote_decode(void)//[ch35793][ch30721][ch20989][ch25968]
{
 TCNT1=0X00;      
 while(digitalRead(8))//[ch26159][ch39640][ch23601][ch31561][ch24453]
 {
   if(TCNT1>=1563)  //[ch24403][ch39640][ch30005][ch24179][ch25345][ch32493][ch26102][ch38388][ch36229][ch36807]100ms[ch65292][ch34920][ch26126][ch27492][ch26102][ch27809][ch26377][ch25353][ch38190][ch25353][ch19979]
   {
     ir_code=0x00ff;// [ch29992][ch25143][ch32534][ch30721][ch20540]
     adrL_code=0x00;//[ch38190][ch30721][ch21069][ch19968][ch20010][ch23383][ch33410][ch20540]
     adrH_code=0x00;//[ch38190][ch30721][ch21518][ch19968][ch20010][ch23383][ch33410][ch20540]
     return;
   }  
 }

 //[ch22914][ch26524][ch39640][ch30005][ch24179][ch25345][ch32493][ch26102][ch38388][ch19981][ch36229][ch36807]100ms
 TCNT1=0X00;

 while(!(digitalRead(8))); //[ch20302][ch31561][ch24453]
 Pulse_Width=TCNT1;
 TCNT1=0;
 if(Pulse_Width>=140&&Pulse_Width<=141)//9ms
 {

   while(digitalRead(8));//[ch26159][ch39640][ch23601][ch31561][ch24453]
   Pulse_Width=TCNT1;
   TCNT1=0;
   if(Pulse_Width>=68&&Pulse_Width<=72)//4.5ms
   {  
     pulse_deal();
     return;
   }
   else if(Pulse_Width>=34&&Pulse_Width<=36)//2.25ms
   {
     while(!(digitalRead(8)));//[ch20302][ch31561][ch24453]
     Pulse_Width=TCNT1;
     TCNT1=0;
     if(Pulse_Width>=7&&Pulse_Width<=10)//560us
     {
       return;
     }
   }
 }
}

void setup()
{
 int i;//[ch23450][ch20041][ch21464][ch37327]
 for(i=1;i<=7;i++)
   pinMode(i,OUTPUT);//[ch35774][ch32622]1[ch65374]7[ch24341][ch33050][ch20026][ch36755][ch20986][ch27169][ch24335]
 pinMode(IR_IN,INPUT);//[ch35774][ch32622][ch32418][ch22806][ch25509][ch25910][ch24341][ch33050][ch20026][ch36755][ch20837]
 pinMode(9,OUTPUT);
 pinMode(10,OUTPUT);
 pinMode(12,OUTPUT);
 pinMode(13,OUTPUT);
}
void loop()
{
 timer1_init();//[ch23450][ch26102][ch22120][ch21021][ch22987][ch21270]
 while(1)
 {
   remote_decode();  //[ch35793][ch30721]
   remote_deal();   //[ch25191][ch34892][ch35793][ch30721][ch32467][ch26524]
   if(ledSt)
   {
     digitalWrite(LED_r, HIGH);
     digitalWrite(LED_g, LOW);
   }
   else
   {
     digitalWrite(LED_g, HIGH);
     digitalWrite(LED_r, LOW);
   }
 }

}

And here the part i like to integrate:


void remote_automatic(void)
{
 switch (adrL_code) {
   case 74:
 digital_9();
 motor_turn();
 turn  = !turn ;    
 ledSt = !ledSt ;
 
   {// fade in from min to max in increments of 5 points:
    delay(300);
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5)
   // sets the value (range from 0 to 255):
   analogWrite(enablePin, fadeValue);        
   // wait for 30 milliseconds to see the dimming effect    
  delay(300);
 
 // fade out from max to min in increments of 5 points:
 for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5)
   // sets the value (range from 0 to 255):
   analogWrite(enablePin, fadeValue);        
   // wait for 30 milliseconds to see the dimming effect    
   delay(300);
       

Go Up