Это видео недоступно.
Сожалеем об этом.
LESSON 19: Mixing Colors with an RGB LED
HTML-код
- Опубликовано: 31 май 2024
- Homework for Paul McWhorter's All New Arduino R4 WiFi LESSONS for Absolute Beginners, LESSON 19: Mixing Colors with an RGB LED: • Arduino Uno R4 WiFi LE...
Excellent!
Did you think about putting everything in setup instead? You wouldn't need 'done'. Thanks for the tip for lining up the code👍👍
I did not. I used setup() for its "stated" purpose: setting up things for loop(). For this lesson, using setup() would be fine, but for larger projects, maintaining separation of concerns can increase legibility and help with debugging.
@@jeff_wild Of course, another way of looking at it is that you put something that you only want to do once in setup. I would say "There's more than one way to skin a cat" but Frankie🐈 would be very upset!! Some people (probably experienced C++ programmers which definitely rules me out) dispense with setup and loop and just use main.
@@charlotteswift I just tried this on an Arduino simulator (Tinkercad) and it looks like the code doesn't run with a main(). This is not surprising. Unless I miss my guess, the internal Arduino code expects loop() and errors out if it's missing. I also tried calling main() from loop() and that didn't work either, nor did calling main() from setup();
Trying to bypass the Arduino infrastructure sounds like a bad idea.
@@jeff_wild Rats!!! I never said that it would be a good idea to dispense with setup and loop. It was just that I had seen somewhere that it was possible and some people thought that it was a good thing to do. I kind of know that if you put in setup and loop that magically it will do the rest for you and your program (sorry sketch) will actually be using main behind the scenes. I now have to prove to myself (and you) that I can do it. Unfortunately I am rubbish at C++ so watch this space (for some considerable time👎👎🙃🙃🤞🤞) Oh well, I don't have much on for the next three months😁😁Maybe I ought to stick to gardening🙃🙃
@jeff_wild I've just written an incredibly complicated sketch as follows:
int main() {
analogWrite(9, 0);
analogWrite(11, 0);
delay(1000);
}
(pin 11 on my projects board is red and pin 9 is blue) and the LED came on as magenta!!!!!!!!!!!!!!!!! btw I have a common anode RGB LED
??????????????????
Well, I suppose that is proof that you don't need setup, loop, or any idea as to how it works🙃🙃