Jump to content
43oh

[Solved] My Sprinkler code from Arduino not working on Launchpad


Recommended Posts

Hi all,

 

This is my first post in Energia. I have successfully run the below code in UNO and Mega2560, but couldn't get work under Launchpad r1.5 (2553).

 

Can you please help me to overcome this hurdle.

 

The code compiles and upload without any issues in Energia --> launchpad.

But nothing happens when I send the timing for the sprinklers through serial via python.

 

Thanks,

 

 

 

uint8_t ledPin[] = {  2,3,4,5,6,7,8,12}; //Pins assinged for valves
const uint8_t max_valves = 7; 
uint8_t master_valve_id = 7; //master valve is ledPin[10] which is pin 12 in Arduino
uint8_t myInts[max_valves]; // to store the input from serial
unsigned long 
	time_now    = 0,
	time_past   = 0;
unsigned long valves_delays[ max_valves ];
uint8_t current_valve_id = 0;  //first valve to turn on
void setup(){  Serial.begin(9600);  time_past = 
millis();  for (uint8_t thisPin = 0; thisPin < max_valves+1; 
thisPin++)  {    pinMode(ledPin[thisPin], 
OUTPUT);         
digitalWrite(ledPin[thisPin], LOW);  }
}
void loop(){  
if(Serial.available()>0){//      
Serial.println("1");    for (uint8_t thisPin = 0; thisPin 
< max_valves+1; thisPin++)    
{      
DisableValve(thisPin);         
}    time_array();  }  test_time();
}
void test_time(){  for (uint8_t j = 0; j< max_valves; 
j++){    if (valves_delays[j] > 
0)      run_valves();  }}
void time_array(){  for(uint8_t i = 0 ; i < max_valves; i++) 
{    myInts[i] = Serial.parseInt();  }  
uint8_t z,y = 0 ;  for( z = 0 ; z < max_valves; z++) 
{   y  = y + myInts[z];  }  if (y > 
0){     
convert_ul();        
enable_mastervalve();}  else   
DisableValve(master_valve_id);
}
void convert_ul(){  for(uint8_t k = 0 ; k < max_valves; k++) 
{    valves_delays[k] =   60UL * 1000 * 
myInts[k];  }}
void enable_mastervalve(){  
EnableValve(master_valve_id);  current_valve_id = 0;  for 
(uint8_t l=0; l<max_valves; l++){    if 
(valves_delays[current_valve_id] > 0){      
EnableValve(current_valve_id );      
break;    }  }  //  Serial.end();
}
void run_valves(){
  if ( current_valve_id < max_valves)  
{    time_now = millis();
    if ( time_now - time_past > valves_delays[ 
current_valve_id ] )    {      
time_past = time_now;
      DisableValve(current_valve_id );
      current_valve_id = current_valve_id + 1;
      if ( current_valve_id < max_valves ){
        if 
(valves_delays[current_valve_id] > 
0)          
EnableValve(current_valve_id );        
else {          
jump_valve_id();          if ( 
current_valve_id < 
max_valves)            
EnableValve(current_valve_id 
);          
else            
DisableValve(master_valve_id);        
}      }      
else        
DisableValve(master_valve_id);
    }  }}
void jump_valve_id(){  uint8_t l =0;  uint8_t m = 
max_valves - current_valve_id;
  for (uint8_t l=0; l<m; l++){    if 
(valves_delays[current_valve_id] > 0)      
break;
    else      current_valve_id = 
current_valve_id + 1;  }}
void DisableValve(uint8_t valve_id ){  
digitalWrite(ledPin[valve_id], LOW);  valves_delays[valve_id] = 
0;Serial.println("Off"); }
void EnableValve(uint8_t valve_id ){  
digitalWrite(ledPin[valve_id], HIGH);  Serial.println("On");
}

spr.txt

Link to post
Share on other sites

Thanks for the reply energia,

 

Yes the Serial port is working. I also checked with the ASCII table and it is working as well.

 

To make things simple I also made the change

 

 

 

void time_array(){  for(uint8_t i = 0 ; i < max_valves; 
i++){   
myInts[i] = 2; // Serial.parseInt(); 
}

 

But no change, there is no HIGH output in any of the output pins.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...