Created
January 29, 2020 22:51
-
-
Save 0xF6/07c13cbc42efd7e1be48cc82530b2535 to your computer and use it in GitHub Desktop.
Display CO2 ppm value contains in air.
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 "Arduino.h" | |
#include "TM74.h" | |
#define DIO 5 | |
#define RCLK 6 | |
#define SCLK 7 | |
#define ALARM 10 | |
TM74 display(SCLK, RCLK, DIO); | |
const int analogInPin = A5; | |
const int ledPin = 13; | |
int raw_adc = 0; | |
float sensorValue = 0; | |
void setup() { | |
pinMode(ledPin, OUTPUT); | |
pinMode(ALARM, OUTPUT); | |
} | |
void loop() { | |
raw_adc = analogRead(analogInPin); | |
sensorValue = ((10000.0 / 4096.0) * (raw_adc )) + 200; | |
if (sensorValue >= 800) | |
{ | |
digitalWrite(ledPin, HIGH); | |
digitalWrite(ALARM, 122); | |
} | |
else | |
{ | |
digitalWrite(ledPin, LOW); | |
digitalWrite(ALARM, LOW); | |
} | |
draw(sensorValue); | |
} | |
String ValueToString(int value){ | |
if(value > 9999) | |
return "DEAD"; | |
if(value > 999) | |
return String(value); | |
if(value > 99) | |
return String("0") + String(value); | |
if(value > 9) | |
return String("00") + String(value); | |
return String("000") + String(value); | |
} | |
void draw(int CO_value){ | |
String result = ValueToString(CO_value); | |
Segment segs[] = { | |
Segment(result[3]), | |
Segment(result[2]), | |
Segment(result[1]), | |
Segment(result[0]) | |
}; | |
display.writeSegments(segs, sizeof(segs) / sizeof(Segment)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
specs: