Skip to content

Commit

Permalink
added serial commands
Browse files Browse the repository at this point in the history
  • Loading branch information
RBEGamer committed Apr 1, 2019
1 parent ee4985b commit 1e13a50
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 27 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ After power up the clock you can use the buttons to change the time.
Select with the `OK-BUTTON` if you want to change minutes or hours and change them with the `+ / - Buttons`.


### SERIAL COMMANDS
The clock send out a current time string `_t_hours_mins_secs_` the t at the beginning is the time identifier.

To set the clock using serial you can use the st time command: `_st_hours_mins_`

note the `_` at the end this has to be send, with an new line charater.


# PICTURES


Expand Down
113 changes: 86 additions & 27 deletions src/nixie_driver/nixie_driver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ for (int i=0; binval && i < sizeof(bcdval) * 8; i+=4) {
return bcdval;
}

String readString;
String getValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = {
0, -1};
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++)
{
if (data.charAt(i) == separator || i == maxIndex)
{
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i + 1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}




void update_mode_led(){
digitalWrite(led_hour_pin, LOW);
Expand All @@ -55,6 +76,17 @@ if(mode == 0){
// digitalWrite(led_on_pin, HIGH);
// mode= 2;
}


Serial.print("_t_");
Serial.print(hours);
Serial.print("_");
Serial.print(mins);
Serial.print("_");
Serial.print(secs);
Serial.println("_");


}


Expand All @@ -72,7 +104,7 @@ if(mode == 0){

void setup() {


Serial.begin(9600);
delay(5000);
pinMode(storePin, OUTPUT);
pinMode(shiftPin, OUTPUT);
Expand Down Expand Up @@ -154,12 +186,32 @@ if((secs % 2) == 0){
digitalWrite(shiftPin, HIGH);
}
digitalWrite(storePin, HIGH);

Serial.print("_t_");
Serial.print(hours);
Serial.print("_");
Serial.print(mins);
Serial.print("_");
Serial.print(secs);
Serial.println("_");


}



void update_rtc(){
rtc.adjust(DateTime(2000, 1, 1, hours, mins, 0));

Serial.print("_t_");
Serial.print(hours);
Serial.print("_");
Serial.print(mins);
Serial.print("_");
Serial.print(secs);
Serial.println("_");


}

void loop () {
Expand All @@ -169,34 +221,41 @@ void loop () {
mins=now.minute();
secs=now.second();

// ):

/*
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA())){
for(int i = 0;i< 7;i++){
delay(100);
digitalWrite(led_hour_pin, LOW);
delay(100);
digitalWrite(led_hour_pin, LOW);
}
} // this also sets the newNMEAreceived() flag to false
hours =GPS.hour;
mins = GPS.minute;
secs = GPS.seconds;
update_rtc_gps();
Serial.println("GPSGOT");
play_sound(10);
for(int i = 0;i< 4;i++){
delay(20);
digitalWrite(led_on_pin, LOW);
delay(20);
digitalWrite(led_on_pin, LOW);

while (Serial.available())
{
delay(30); //delay to allow buffer to fill
if (Serial.available() > 0)
{
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
}
}
update_mode_led();
}
*/

if (readString.length() > 0)
{

if (getValue(readString, '_', 1) == "st")
{

int tmp_hours =getValue(readString, '_', 2).toInt();
int tmp_mins =getValue(readString, '_', 3).toInt();


if(tmp_hours > 0 && tmp_hours <24 && tmp_mins > 0 && tmp_mins < 60){
hours = tmp_hours;
mins = tmp_mins;
update_rtc();
}else{
Serial.println("_error_params.out.of.range_");
}


}
readString = "";
}



Expand Down

0 comments on commit 1e13a50

Please sign in to comment.