matrix.writeDigitRaw(0, 0b00111000);
Syntax:
0b0GFEDCBA
A
F B
G
E C
D
0b01111000 = t
0b01110110 = H
0b01110011 = P
Eksempel program med 7-segment display:
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
Adafruit_7segment matrix = Adafruit_7segment();
float
current_temperature = -9.99,
current_humidity = 67.992009,
current_pressure = 1009.51,
current_lux = 109.51443;
uint8_t
display_status = 1;
const uint8_t
inputPinButton = 10,
outputPinReset = 9,
outputPinLed = 8;
const uint16_t
buttonDisplayTime = 500,
buttonResetTime = 5000;
unsigned long
buttonPushMillis;
bool
buttonTimerStarted,
buttonActionFinished = false,
buttonActionDisplayFinished = false;
void updateDisplay() {
Serial.println("TEST");
if(display_status == 1) {
matrix.print(current_temperature, current_temperature < -9.9 ? 0 : 1);
matrix.writeDigitRaw(0, 0b01111000);
matrix.writeDisplay();
}
if(display_status == 2) {
matrix.print(current_humidity, 0);
matrix.writeDigitRaw(0, 0b01110110);
matrix.writeDisplay();
}
if(display_status == 3) {
matrix.print(current_pressure, 0);
matrix.writeDigitRaw(0, 0b01110011);
if(current_pressure >= 999.5) {
matrix.writeDigitRaw(1, 0b01110101);
}
matrix.writeDisplay();
}
if(display_status == 4) {
bool writeK = false;
float current_lux2;
if(current_lux >= 999.5) {
current_lux2 = current_lux/1000.00;
writeK = true;
}
matrix.print(writeK ? current_lux2 : current_lux, writeK ? 1 : 0);
matrix.writeDigitRaw(0, 0b00111000);
if(writeK) {
matrix.writeDigitRaw(1, 0b01110101);
}
matrix.writeDisplay();
}
}
void updateDisplayStatus()
{
if(display_status == 4) {
display_status = 1;
return;
}
if(display_status == 3) {
display_status = 4;
return;
}
if(display_status == 2) {
display_status = 3;
return;
}
if(display_status == 1) {
display_status = 2;
return;
}
}
void resetArduino() {
Serial.println("HEI");
}
void setup() {
pinMode(inputPinButton, INPUT_PULLUP);
pinMode(outputPinReset, OUTPUT);
digitalWrite(outputPinReset, HIGH);
matrix.begin(0x70);
updateDisplay();
}
void loop() {
int c = !digitalRead(inputPinButton);
if(!c) {
buttonPushMillis = 0;
buttonTimerStarted = false;
buttonActionFinished = false;
buttonActionDisplayFinished = false;
} else {
if(!buttonTimerStarted) {
buttonPushMillis = millis();
}
buttonTimerStarted = true;
}
if(buttonTimerStarted) {
if(!buttonActionDisplayFinished && (millis()-buttonPushMillis > buttonDisplayTime)) {
buttonActionDisplayFinished = true;
updateDisplayStatus();
updateDisplay();
}
if(!buttonActionFinished && (millis()-buttonPushMillis > buttonResetTime)) {
buttonPushMillis = 0;
buttonTimerStarted = false;
buttonActionFinished = true;
resetArduino();
}
}
}