Created
December 4, 2020 10:44
-
-
Save JesusTinoco/286e26987ee34579e8d5b9ea868212ee to your computer and use it in GitHub Desktop.
Practica4 - Arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Timer5.h> | |
// Identificación de pines digitales | |
int pinTone = 8; | |
int pinBoton = 4; | |
int pinRojo = 1; | |
int pinVerde = 3; | |
int pinAmarillo = 5; | |
// Identificación de pines analógicos | |
int pinTempSensor = A0; | |
// Umbrales temperatura | |
int umbralRojo = 17; | |
int tempSensor=0; | |
float tempVoltage=0; | |
float tempDegrees; | |
volatile int count = 0; | |
void setup() | |
{ | |
pinMode(pinBoton,INPUT); | |
pinMode(pinRojo,INPUT); | |
attachInterrupt(digitalPinToInterrupt(pinRojo), blink, RISING); | |
MyTimer5.attachInterrupt(timer); | |
pinMode(pinVerde, OUTPUT); | |
pinMode(pinAmarillo, OUTPUT); | |
pinMode(pinTone, OUTPUT); | |
digitalWrite(pinVerde, HIGH); | |
Serial.begin(9600); // Inicialización comunicación serie PC-Arduino | |
} | |
void loop() | |
{ | |
if(count > 9) { | |
Serial.println("END!"); | |
measureTemperature(); | |
printTemperature(); | |
MyTimer5.end(); | |
digitalWrite(pinRojo, LOW); | |
digitalWrite(pinAmarillo, LOW); | |
digitalWrite(pinVerde, HIGH); | |
count = 0; | |
} | |
if( digitalRead(pinBoton) ) { | |
digitalWrite(pinRojo, HIGH); | |
} | |
if(tempDegrees < umbralRojo) | |
{ | |
noTone(pinTone); | |
} | |
else | |
{ | |
tone(pinTone, 200); | |
} | |
delay(1000); | |
} | |
void timer() { | |
count++; // count number of toggles | |
Serial.println(count); | |
} | |
void measureTemperature() { | |
tempSensor = analogRead(pinTempSensor); | |
tempVoltage = tempSensor * (3300/1024); //in miliVolt | |
tempDegrees = (tempVoltage - 500) / 10; | |
} | |
void printTemperature() { | |
Serial.print(" Tiempo (sg) "); | |
Serial.print(millis()/1000); | |
Serial.print(" tempSensor "); | |
Serial.print(tempSensor); | |
Serial.print(" tempVoltage "); | |
Serial.print(tempVoltage); | |
Serial.print(" tempDegrees "); | |
Serial.println(tempDegrees); | |
} | |
void blink() { | |
Serial.println("BLINK"); | |
count = 0; | |
digitalWrite(pinAmarillo, HIGH); | |
digitalWrite(pinVerde, LOW); | |
MyTimer5.begin(1); // 200=for toggle every 5msec | |
MyTimer5.start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment