Ora

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
824 B
3
Indexable
Never
#include <avr/pgmspace.h>

// Aici incarcam in FLASH toate cifrele care ne treb, intr-un String
// ca tre sa le avem in memorie neaparat, nu putem realTime.
const char s0[] PROGMEM = ":0123456789";

void setup() {
  Serial.begin(9600);
  while (!Serial);  // wait for serial port to connect. Needed for native USB
  Serial.println("OK");
}


void loop() {
  
  // Aici o sa fie variabila ta. O inlocuiesti cu cea care vine de altundeva.
  char *hour = "12:20:30";

  for (int i = 0; i < strlen(hour); i++) {
    char currChar = hour[i];
    if (currChar == ':') {
       Serial.print((char)pgm_read_byte(&s0[0]));
    } else {
      int pos = currChar - '0';
       Serial.print((char)pgm_read_byte(&s0[pos + 1]));
    }
    
      // Necessary casts and dereferencing, just copy.
    delay(500);
  }
  Serial.print('\n');
}