Timer and Delay

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mjpcarbon
 
Posts: 436
Joined: Fri Nov 29, 2013 8:57 pm

Timer and Delay

Post by mjpcarbon »

In this sketch which works well with the exception of the timer I wanted to do the two following things.
First blink the LED at a given temp (which works fine)
Then at a second temperature I wanted to very quickly toggle a conventional coil relay(the one in the starter kit)
The LED works but the delay function led me to "Timer" I did my best to get this on my own but all I can do is get the relay to tick away. Nothing I seem to do changes the rate of tick.
I stopped short of trying to get it to activate at a given temp because I wasnt able to get the relay to work as I wanted to

Code: Select all

  
   ****************************************************/

#include "Adafruit_MAX31855.h"
#include <LiquidCrystal.h>
#include "Timer.h"

Timer t;

int thermoCLK = 2;
int thermoCS = 4;
int thermoDO = 5;
int ET;
int led = 13;
int pin = 6;






// Initialize the Thermocouple
Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

  
void setup() {
  Serial.begin(9600);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  
  lcd.print("Engine Saver");
  // wait for MAX chip to stabilize
  delay(500);
  
  pinMode(led, OUTPUT);
  pinMode(6, OUTPUT);
  
}

void loop() {
  // basic readout test, just print the current temp
   lcd.setCursor(0, 0);
   //lcd.print("Int. Temp = ");
   //lcd.println(thermocouple.readInternal());
   //lcd.print("  "); 
   
   //t.update();  
   
   double c = thermocouple.readCelsius();
   lcd.setCursor(0, 1);
   if (isnan(c)) 
   {
     lcd.print("T/C Problem");
   } 
   else 
   {
     lcd.print("EGT = "); 
     lcd.print(c * 1.8 + 32);
     lcd.print("  "); 
     
     ET = (c * 1.8 + 32);
     if (ET > 75) digitalWrite(led,HIGH); delay(500); digitalWrite(led,LOW); delay(50);
     if (ET < 75) digitalWrite(led,LOW);
     //if (ET > 81) digitalWrite(RLY, HIGH); delay(50); digitalWrite(RLY, LOW); delay(50);
     //if (ET > 81) r.oscillate(6, 50, HIGH,5); // the 5 is how many times it blinks
     //if (ET > 81) r.oscillate(6, 10, HIGH);
     t.oscillate(6,5,HIGH);
     t.update();
     
     Serial.println(ET);
     
   }
 
   //delay(1000);
}[code]  
   ****************************************************/

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Timer and Delay

Post by adafruit_support_mike »

I think the BlinkWithoutDelay sketch will give you an example of what you're trying to do: http://arduino.cc/en/Tutorial/BlinkWithoutDelay

User avatar
mjpcarbon
 
Posts: 436
Joined: Fri Nov 29, 2013 8:57 pm

Re: Timer and Delay

Post by mjpcarbon »

I looked at that tutorial and see it uses the if command so in my sketch I need to flash the LED "if" temp > so can I do an if if statement ?

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Timer and Delay

Post by adafruit_support_mike »

Yes.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”