// ==== Program Open windows ===
// Created by Pong Porn 5/8
// Modify date: 06/08/2024
// =============================
#include <OneWire.h>
#include <DallasTemperature.h>
#define pulPin 8
#define dirPin 9
#define enaPin 10
#define SwPinL 2
#define SwPinR 3
int currentAngle = 0;
int Angle = 0;
float TmpGet;
//int LM35 = A0;
//int val;
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(11);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600); // Bus rate for print out
sensors.begin();
Serial.println("Arduino Digital Temperature // Serial Monitor Version"); //Print a message
pinMode(pulPin, OUTPUT); // Step pin
pinMode(dirPin, OUTPUT); // direction pin
pinMode(enaPin, OUTPUT); // Enable pin driver
pinMode(SwPinL, INPUT_PULLUP); // Switch Left Input pull up no need Resistor
pinMode(SwPinR, INPUT_PULLUP); // Switch Right Input pull up no need Resistor
// Interrupt
// Format attachInterrupt(interrupt, ISR, mode)
// attachInterrupt(1, detector, RISING);
// Number 1 is Interrupt 1 at pin 3
// detector is function
// RISING : if status change from Low to High it go to dector function
digitalWrite(enaPin,LOW); // Enable = Low, High = Disable
// digitalWrite(dirPin,Low); // This si direction.
}
void loop() {
byte btnL = digitalRead(SwPinL); // Get Limit sw left
byte btnR = digitalRead(SwPinR); // Get Limit sw right
sensors.requestTemperatures();
TmpGet = sensors.getTempCByIndex(0);
// Print value limit switch
Serial.println("BtnLeft=" + String(btnL) + ";BtnRight=" + String(btnR) + ";Temp = " + String(TmpGet));
// temp Sensor section
// val = analogRead(LM35);
// float mv = (val/1024.0)*5000;
// float temp = mv/10; // This is C
/* LM35
Serial.println("====");
Serial.print("TEMPRATURE = ");
Serial.print(temp);
Serial.print("*C");
Serial.println();
*/
// Send the command to get temperatures
// Serial.print("Temperature is: ");
//Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
//Update value every 1 sec.
if (btnL==LOW && btnR==HIGH && TmpGet < 35.5 ) {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
for(int x = 0; x < 200; x++) {
digitalWrite(pulPin,HIGH);
delayMicroseconds(1500);
digitalWrite(pulPin,LOW);
delayMicroseconds(1500);
}
}
delay(1000); // One second delay
if (btnL==HIGH && btnR==LOW && TmpGet > 35.5) {
digitalWrite(dirPin,LOW); //Changes the direction of rotation
for(int x = 0; x < 200; x++) {
digitalWrite(pulPin,HIGH);
delayMicroseconds(1500);
digitalWrite(pulPin,LOW);
delayMicroseconds(1500);
}
}
delay(1000);
}
void detector() {
//Prepare Detector sensor or interrupt switch
}