Go Down

Topic: "Scheduler" library for Due ! (Read 145 times) previous topic - next topic

raghda

hey  :D
 I have a problem in the following code but I can't find where is the error exactly !
the problem is when Upload the code on Due , the "loop4" not work as expected !
loop4 should determine the time in minutes and seconds and count down until the time become zero...BUT on the LCD it doesn't count down !!

here the code .. please HELP!



#include <Scheduler.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
float t,tp,c,tw; //temperature, TMP, conductivity,target weight
int T= A0;
int TP= A1;
int C= A3;
int TW= A4;
int puzz = 36;
int x,y;

void setup() {
 

pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
pinMode(9,OUTPUT);
pinMode(puzz, OUTPUT);
 
lcd.begin(16, 4);
lcd.setCursor(0,0);
lcd.print("T=");
lcd.setCursor(8,0);
lcd.print("TMP=");
lcd.setCursor(0,1);
lcd.print("Cond=");
lcd.setCursor(0,2);
lcd.print("Time Left= ");

tw= analogRead(TW);
tw= tw*300/1023;

Scheduler.startLoop(loop1);
Scheduler.startLoop(loop2);
Scheduler.startLoop(loop3);
Scheduler.startLoop(loop4);
}

void loop() {
  if(tw>0) {
 t= analogRead(T);
 t= t*500/1023;
 lcd.setCursor(2,0);
 lcd.print(t,1);
 
 if (t > 38) {
    digitalWrite(puzz, HIGH);
     lcd.setCursor(0,3);
     lcd.print("High Temperature");
     delay (1000);
  }
  else {
      if (t < 36) {
    digitalWrite(puzz, HIGH);
     lcd.setCursor(0,3);
     lcd.print("Low Temperature");
     delay (1000);
  }
  else {
    digitalWrite(puzz, LOW);
    lcd.setCursor(0,3);
    lcd.print("                ");
  }}
 
 tp= analogRead(TP);
 tp=tp*5/1023;
 tp=400-(tp*(300/3)) ;
 lcd.setCursor(12,0);
 lcd.print(tp,0);
  if (tp > 365 ) {
    digitalWrite(puzz, HIGH);
     lcd.setCursor(0,3);
     lcd.print("High Pressure        ");
     delay (1000);
  }
  else {
     if (tp < 345) {
     digitalWrite(puzz, HIGH);
     lcd.setCursor(0,3);
     lcd.print("Low Pressure        ");
     delay (1000);
  }
  else {
    digitalWrite(puzz, LOW);
   lcd.setCursor(0,3);
    lcd.print("                ");
  }}
 
 c= analogRead(C);
 c=c*5/1023;
 c=24/(c+.07);
 lcd.setCursor(5,1);
 lcd.print(c,1);
 if (c > 14.5) {
    digitalWrite(puzz, HIGH);
     lcd.setCursor(0,3);
     lcd.print("High Conductivity ");
     delay (1000);
  }
  else{
    if (c < 13.5) {
    digitalWrite(puzz, HIGH);
     lcd.setCursor(0,3);
     lcd.print("Low Conductivity ");
     delay (1000);
  }
  else {
   digitalWrite(puzz, LOW);
  lcd.setCursor(0,3);
    lcd.print("                ");
}}}}


void loop1(){
  if (tw>0) {
  analogWrite(7,128);
}}


void loop2(){
   if (tw>0) {
  analogWrite (6,128);
}}


void loop3(){
   if (tw>0) {
  analogWrite(9,128);
}}


void loop4(){
 if (tw>0)
{
  x=tw/60;
  lcd.setCursor(11,2);
     lcd.print(x,1);
     lcd.print(":");
     y=tw-(60*x);
     lcd.print(y,1);
      lcd.print("   ");
     delay(1000);
     tw=tw-1;
}
else
{ digitalWrite(puzz, HIGH);
  analogWrite(7,0);
  analogWrite(6,0);
  analogWrite(9,0);
 
  lcd.clear();
  while (1) {
  lcd.setCursor(0,0);
  lcd.print("FINISHED");
 lcd.setCursor(0,1);
  lcd.print("Turn Power Off");
  lcd.setCursor(0,3);
  lcd.print("Wish a HAPPY day");
}}
yield();
 }

MorganS

Please use [ code ] tags, it makes it easier to read.

You declare a number of variables int TW = 4; but then you use other variables like if (tw>0). I am surprised that this will even compile. TW is not the same variable as tw.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy