//TIL311 display multiplexer
#include <Average.h>
// Arduino pins connected to the 4511
const uint8_t LedA = 2;
const uint8_t LedB = 3;
const uint8_t LedC = 4;
const uint8_t LedD = 5;
// Arduino pins connected to the segment driver transistors
const uint8_t Led1 = 6;
const uint8_t Led2 = 7;
const uint8_t Led3 = 8;
const uint8_t Led4 = 9;
const uint8_t Led5 = 10;
const uint8_t Led6 = 11;
Average<float> avemeas(10);
float measavg = 0;
static int d = 10;
void setup()
{
// Let the Arduino know which pins go where
pinMode(LedA, OUTPUT);
pinMode(LedB, OUTPUT);
pinMode(LedC, OUTPUT);
pinMode(LedD, OUTPUT);
pinMode(Led1, OUTPUT);
pinMode(Led2, OUTPUT);
pinMode(Led3, OUTPUT);
pinMode(Led4, OUTPUT);
pinMode(Led5, OUTPUT);
pinMode(Led6, OUTPUT);
digitalWrite(Led1, LOW);
digitalWrite(Led2, LOW);
digitalWrite(Led3, LOW);
digitalWrite(Led4, LOW);
digitalWrite(Led5, LOW);
digitalWrite(Led6, LOW);
}
void loop()
{
// double measavg = 999999;
float meas = analogRead(2) / 1023.00 * 1000.00;
// float meas = bme.readTemperature() * 100;
avemeas.push(meas);
measavg = avemeas.mean();
print_number(measavg);
}
void print_number(long n) {
set_digit(Led1, d, n/100000);
set_digit(Led2, d, n/10000 );
set_digit(Led3, d, n/1000 );
set_digit(Led4, d, n/100 );
set_digit(Led5, d, n/10 );
set_digit(Led6, d, n/1 );
}
void set_digit(const uint8_t led, const long d, const long value) {
set_number(value);
digitalWrite(led, LOW);
delay(d);
digitalWrite(led, HIGH);
}
void set_number(const long n) {
static const struct number {
uint8_t d;
uint8_t c;
uint8_t b;
uint8_t a;
} numbers[] = {
{ LOW, LOW, LOW, LOW}, /* 0 */
{ LOW, LOW, LOW, HIGH}, /* 1 */
{ LOW, LOW, HIGH, LOW}, /* 2 */
{ LOW, LOW, HIGH, HIGH}, /* 3 */
{ LOW, HIGH, LOW, LOW}, /* 4 */
{ LOW, HIGH, LOW, HIGH}, /* 5 */
{ LOW, HIGH, HIGH, LOW}, /* 6 */
{ LOW, HIGH, HIGH, HIGH}, /* 7 */
{HIGH, LOW, LOW, LOW}, /* 8 */
{HIGH, LOW, LOW, HIGH}, /* 9 */
{HIGH, LOW, HIGH, LOW}, /* A */
{HIGH, LOW, HIGH, HIGH}, /* B */
{HIGH, HIGH, LOW, LOW}, /* C */
{HIGH, HIGH, LOW, HIGH}, /* D */
{HIGH, HIGH, HIGH, LOW}, /* E */
{HIGH, HIGH, HIGH, HIGH}, /* F */
};
digitalWrite(LedA, numbers[n%10].a);
digitalWrite(LedB, numbers[n%10].b);
digitalWrite(LedC, numbers[n%10].c);
digitalWrite(LedD, numbers[n%10].d);
}
Comments