Skip to content

Instantly share code, notes, and snippets.

@moomdate
Created June 19, 2017 17:28
Show Gist options
  • Save moomdate/fc52ae082aa6d885a7837bdc109959d9 to your computer and use it in GitHub Desktop.
Save moomdate/fc52ae082aa6d885a7837bdc109959d9 to your computer and use it in GitHub Desktop.
#include <SPI.h>
#include "LedMatrix.h"
#include "ClosedCube_HDC1080.h"
ClosedCube_HDC1080 hdc1080;
#define NUMBER_OF_DEVICES 1
#define CS_PIN D8
LedMatrix ledMatrix = LedMatrix(NUMBER_OF_DEVICES, CS_PIN);
void setup() {
Serial.begin(115200); // For debugging output
ledMatrix.init();
ledMatrix.setIntensity(4); // range is 0-15
hdc1080.begin(0x40);
ledMatrix.clear();
ledMatrix.commit();
}
void loop() {
// ledMatrix.clear();
//ledMatrix.commit();
int temp = hdc1080.readTemperature()*10;
int humi = hdc1080.readHumidity()*10;
Send2MAX7129(8, int(temp/100), 0);
Send2MAX7129(7, (temp/10)%10, 1);
Send2MAX7129(6, (int)temp%10, 0);
Send2MAX7129(5, 12, 0);
Send2MAX7129(4, int(humi/100), 0);
Send2MAX7129(3, (humi/10)%10, 1);
Send2MAX7129(2, (int)humi%10, 0);
Send2MAX7129(1, 16, 0);
Serial.println(int(temp/10));
delay(200);
}
//===================================================
//===================================================
void Send2MAX7129(byte SegPosition, byte Value, bool dotDigit)
{ const static byte charTable [] =
{ B01111110, B00110000, B01101101, B01111001,
B00110011, B01011011, B01011111, B01110000,
B01111111, B01111011, B01110111, B00011111,
B00001101, B00111101, B01001111, B01000111,0x17
};
Value = charTable[Value];
if (dotDigit == 1) Value |= 0x80;
digitalWrite(CS_PIN, LOW);
SPI.transfer (SegPosition);
SPI.transfer (Value);
digitalWrite (CS_PIN, HIGH);
// Serial.print(Value);
}
//===================================================
// ##SegPosition >> 87654321 ##SegData >> tabcdefg
//===================================================
void SendData2MAX7129(byte SegPosition, byte SegData)
{ digitalWrite(CS_PIN, LOW);
SPI.transfer (SegPosition);
SPI.transfer (SegData);
digitalWrite (CS_PIN, HIGH);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment