hi comunity!
i would like some help with one project i'm trying to built....
So ... i have a 7segment thermometer with 2 shift registers with an rgb led no show me some events from my pc (one old project of mine)
and a 8*8 matrix led with max7219 +rtc binary clock ,built a week ago....
So im trying to merge those two, to reclaim back one of my arduinos...
the code im using for the thermometer is this
#include <OneWire.h>
#include <DallasTemperature.h>
// pin setups
int latchPin = 9;
int clockPin = 10;
int dataPin = 8;
int tempPin = 7;
int ledg = 5;
int ledb = 4;
int ledr = 3;
// librraries for connecting to sensor
OneWire oneWire(tempPin);
DallasTemperature tempSens(&oneWire);
boolean blink = false; // holds our current state
int state;
int INTERVAL = 100; // led blink rate in milliseconds
int de = 100;
// characters for displaying on 7-seg display 0-9
byte numberSet[12] = {
B01111101,B01000100,B01111010,B01101110,B01000111,B00101111,
B00111111,B01100100,B01111111,B01101111 ,B00000010, B00000000
};
void setup() {
Serial.begin(9600);
// init serial
// Serial.begin(9600);
// init temp sensor
tempSens.begin();
// set pin modes for shift registors
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(ledg, OUTPUT);
pinMode(ledb, OUTPUT);
pinMode(ledr, OUTPUT);
}
void loop() {
tempSens.requestTemperatures();
float t = tempSens.getTempCByIndex(0);
// Serial.println(t);
if (t>=10){
// cast to float (only have 2 digits to use on display)
int rT = (int)t;
// get units of temp
int units = rT % 10;
// get tens value of temp
rT = rT/10;
int tens = rT % 10;
displayNumb(units, tens);
delay(100);
}
else if (t>=0 && t<10){
int rT = (int)t;
// get units of temp
int units = rT % 10;
// get tens value of temp
int tens = 11;
displayNumb(units, tens);
delay(100);
}
else if (t<0){
double d = t;
d = -d;
int rT = (int)d;
// get units of temp
int units = rT % 10;
// get tens value of temp
int tens = 10;
displayNumb(units, tens);
delay(100);
}
if(Serial.available() > 0)
blink = Serial.read();// 48 is 0 is ASCII
// if(digitalRead(bPin) == LOW) // button pressed
// blink = false;
// msg
if(blink == 50) {
state = 1;
digitalWrite(ledr, HIGH); // turn the LED on (HIGH is the voltage level)
delay(de); // wait for a second
digitalWrite(ledr, LOW); // turn the LED off by making the voltage LOW
delay(de); // wait for a second
digitalWrite(ledg, HIGH); // turn the LED on (HIGH is the voltage level)
delay(de); // wait for a second
digitalWrite(ledg, LOW); // turn the LED off by making the voltage LOW
delay(de); // wait for a second
digitalWrite(ledb, HIGH); // turn the LED on (HIGH is the voltage level)
delay(de); // wait for a second
digitalWrite(ledb, LOW); // turn the LED off by making the voltage LOW
delay(de); // wait for a second
}
else //on
if(blink == 49) {
state = 2;
digitalWrite(ledg, HIGH);
}
else //off
if(blink == 48) {
state = 3;
digitalWrite(ledg, LOW);
digitalWrite(ledb, LOW);
digitalWrite(ledr, LOW);
}
else //network error
if(blink == 51) {
state = 1;
digitalWrite(ledb, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(ledb, LOW); // turn the LED off by making the voltage LOW
delay(50); // wait for a second
digitalWrite(ledb, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(ledb, LOW); // turn the LED off by making the voltage LOW
delay(50); // wait for a second
digitalWrite(ledg, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(ledg, LOW); // turn the LED off by making the voltage LOW
delay(50); // wait for a second
digitalWrite(ledg, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(ledg, LOW); // turn the LED off by making the voltage LOW
delay(50); // wait for a second
}
}
void displayNumb(int a, int b) {
// get the code for the numbers
byte bitsB = numberSet[a];
byte bitsA = numberSet[b];
// set ready to shift out
digitalWrite(latchPin, LOW);
// shift units
shiftOut(dataPin, clockPin, bitsA);
// shift tens
shiftOut(dataPin, clockPin, bitsB);
// shift out data
digitalWrite(latchPin, HIGH);
}
// shift the data out to the shift registors
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
int i=0;
int pinState;
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
// iterate over each bit in the myDataOut byte
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
digitalWrite(myDataPin, pinState);
digitalWrite(myClockPin, 1);
digitalWrite(myDataPin, 0);
}
digitalWrite(myClockPin, 0);
}
and the code for the rtc binary clock is this
/*
Wiring for the MAX72xx LED matrix:
Pin D12 is connected to the DIN (DataIn)
Pin D11 is connected to CS (LOAD)
Pin D13 is connected to the CLK
DS3231RTC (I2C bus)
Nano A4 to sca, A5 to scl.
*/
#include <DS1307RTC.h>
#include <Time.h>
#include <Wire.h>
#include "LedControl.h"
//Pin definition constants
const int mDataIn=12, mLoad=11, mClk=13; //Max7219 LED matrix
int h1, h2, m1, m2, s1, s2, d1, d2, mo1, mo2; // Each digit
int tChange; //Scratch used during change time via pushbutton
// Matrix library instance
LedControl lc=LedControl(mDataIn, mClk, mLoad,1); //Pin assignments and number of matrices (1)
void setup() {
// Initialize pushbutton pins as input:
// Remove comments to set the system time to a hard-coded date and time,
// then set the RTC from the system time.
// Hr Min Sec dd mm yyyy
// setTime(19, 43, 30, 8, 12, 2014);
// RTC.set(now()); //set the RTC from the system time
// Notify Arduimo that the RTC is the external time provider
setSyncProvider(RTC.get);
//Initialize the MAX72XX in power-saving mode.
lc.shutdown(0,false);
lc.setIntensity(0,1); // Set brightness to a low value
lc.clearDisplay(0); // Clear the display
delay(100); // Wait after initializing display
Serial.begin(9600);
}
void loop() {
//Isolate hours, minutes, seconds, one digit to each LED matrix column.
h1=n1(hour());
h2=n2(hour());
m1=n1(minute());
m2=n2(minute());
s1=n1(second());
s2=n2(second());
d1=n1(day());
d2=n2(day());
mo1=n1(month());
mo2=n2(month());
// Cast as (change integer to) byte, write to LED row.
// (Row runs from pin to pin on model used.)
lc.setRow(0,0,byte(h1));
lc.setRow(0,1,byte(h2));
lc.setRow(0,3,byte(m1));
lc.setRow(0,4,byte(m2));
lc.setRow(0,6,byte(s1));
lc.setRow(0,7,byte(s2));
}
int n1(int num) // Function to isolate first digit of 2-digit integer
{
num = num / 10; //Integer division by 10 (discard remainder)
return num;
}
int n2(int num) // Function to isolate second digit of 2-digit integer
{
num = num % 10; //Modulo division by 10 (keep remainder only)
return num;
}