Skip to main content

I want to create a LED SunRiseSunrise/Sundown alarmclockalarm clock. Therefore, iI will use a raspberryRaspberry Pi that is sending commands over serial to a Teensy 3.1. Like:

  • "30 Minute Sunrise starting with Color(255,140,0)"
  • "20 Minute Sundown with Color(255,140,0)"
  • "start something else with these 3 parameter.

But iI don't even get the basic serial part working. E.g. iI tried this:

void setup() {
  Serial.begin(9600);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  if (Serial.available() > 0) {
    if (Serial.read() == 'A'){
      int inte1 = Serial.parseInt();
      int inte2 = Serial.parseInt();
      int inte3 = Serial.parseInt();
      int inte4 = Serial.parseInt();
      int inte5 = Serial.parseInt();
      if (Serial.read() == '\n') {
        Serial.print(inte1);
        Serial.print(inte2);
        Serial.print(inte3);
        Serial.print(inte4);
        Serial.println(inte5);
      }
    }
  }
}

I planned to do a case switch afterwards. Inte1 should define sunrise/sundown, Inte2 the minutes, 'Inte3-5' the rgb color.

However, when I enter "A 1 100 100 100" it is not printing anything at all.

What is the best way do get this working?

Thanks in advance!

I want to create a LED SunRise/Sundown alarmclock. Therefore, i will use a raspberry that is sending commands over serial to a Teensy 3.1. Like:

  • "30 Minute Sunrise starting with Color(255,140,0)"
  • "20 Minute Sundown with Color(255,140,0)"
  • "start something else with these 3 parameter.

But i don't even get the basic serial part working. E.g. i tried this:

void setup() {
  Serial.begin(9600);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  if (Serial.available() > 0) {
    if (Serial.read() == 'A'){
      int inte1 = Serial.parseInt();
      int inte2 = Serial.parseInt();
      int inte3 = Serial.parseInt();
      int inte4 = Serial.parseInt();
      int inte5 = Serial.parseInt();
      if (Serial.read() == '\n') {
        Serial.print(inte1);
        Serial.print(inte2);
        Serial.print(inte3);
        Serial.print(inte4);
        Serial.println(inte5);
      }
    }
  }
}

I planned to do a case switch afterwards. Inte1 should define sunrise/sundown, Inte2 the minutes, 'Inte3-5' the rgb color.

However, when I enter "A 1 100 100 100" it is not printing anything at all.

What is the best way do get this working?

Thanks in advance!

I want to create a LED Sunrise/Sundown alarm clock. Therefore, I will use a Raspberry Pi that is sending commands over serial to a Teensy 3.1. Like:

  • "30 Minute Sunrise starting with Color(255,140,0)"
  • "20 Minute Sundown with Color(255,140,0)"
  • "start something else with these 3 parameter.

But I don't even get the basic serial part working. E.g. I tried this:

void setup() {
  Serial.begin(9600);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  if (Serial.available() > 0) {
    if (Serial.read() == 'A'){
      int inte1 = Serial.parseInt();
      int inte2 = Serial.parseInt();
      int inte3 = Serial.parseInt();
      int inte4 = Serial.parseInt();
      int inte5 = Serial.parseInt();
      if (Serial.read() == '\n') {
        Serial.print(inte1);
        Serial.print(inte2);
        Serial.print(inte3);
        Serial.print(inte4);
        Serial.println(inte5);
      }
    }
  }
}

I planned to do a case switch afterwards. Inte1 should define sunrise/sundown, Inte2 the minutes, 'Inte3-5' the rgb color.

However, when I enter "A 1 100 100 100" it is not printing anything at all.

What is the best way do get this working?

Thanks in advance!

Source Link
Markus
  • 111
  • 3

How do I start a function with serial input?

I want to create a LED SunRise/Sundown alarmclock. Therefore, i will use a raspberry that is sending commands over serial to a Teensy 3.1. Like:

  • "30 Minute Sunrise starting with Color(255,140,0)"
  • "20 Minute Sundown with Color(255,140,0)"
  • "start something else with these 3 parameter.

But i don't even get the basic serial part working. E.g. i tried this:

void setup() {
  Serial.begin(9600);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  if (Serial.available() > 0) {
    if (Serial.read() == 'A'){
      int inte1 = Serial.parseInt();
      int inte2 = Serial.parseInt();
      int inte3 = Serial.parseInt();
      int inte4 = Serial.parseInt();
      int inte5 = Serial.parseInt();
      if (Serial.read() == '\n') {
        Serial.print(inte1);
        Serial.print(inte2);
        Serial.print(inte3);
        Serial.print(inte4);
        Serial.println(inte5);
      }
    }
  }
}

I planned to do a case switch afterwards. Inte1 should define sunrise/sundown, Inte2 the minutes, 'Inte3-5' the rgb color.

However, when I enter "A 1 100 100 100" it is not printing anything at all.

What is the best way do get this working?

Thanks in advance!