Untitled

From Wet Peccary, 10 Months ago, written in C, viewed 147 times.
URL https://paste.monocul.us/view/1998f27b Embed
Download Paste or View Raw
  1. #define INTERVAL_MESSAGE1 5000
  2. #define INTERVAL_MESSAGE2 7000
  3. #define INTERVAL_MESSAGE3 11000
  4. #define INTERVAL_MESSAGE4 13000
  5.  
  6. unsigned long time_1 = 0;
  7. unsigned long time_2 = 0;
  8. unsigned long time_3 = 0;
  9. unsigned long time_4 = 0;
  10.  
  11. void print_time(unsigned long time_millis);
  12.  
  13. void setup() {
  14.     Serial.begin(115200);
  15. }
  16.  
  17. void loop() {
  18.     if(millis() > time_1 + INTERVAL_MESSAGE1){
  19.         time_1 = millis();
  20.         print_time(time_1);
  21.         Serial.println("I'm message number one!");
  22.     }
  23.    
  24.     if(millis() > time_2 + INTERVAL_MESSAGE2){
  25.         time_2 = millis();
  26.         print_time(time_2);
  27.         Serial.println("Hello, I'm the second message.");
  28.     }
  29.    
  30.     if(millis() > time_3 + INTERVAL_MESSAGE3){
  31.         time_3 = millis();
  32.         print_time(time_3);
  33.         Serial.println("My name is Message the third.");
  34.     }
  35.    
  36.     if(millis() > time_4 + INTERVAL_MESSAGE4){
  37.         time_4 = millis();
  38.         print_time(time_4);
  39.         Serial.println("Message four is in the house!");
  40.     }
  41. }
  42.  
  43. void print_time(unsigned long time_millis){
  44.     Serial.print("Time: ");
  45.     Serial.print(time_millis/1000);
  46.     Serial.print("s - ");
  47. }

Reply to "Untitled"

Here you can reply to the paste above