State machine programming for Arduino, switch case, table of structs, and table of function pointers

Поделиться
HTML-код
  • Опубликовано: 26 окт 2024
  • НаукаНаука

Комментарии • 16

  • @tingkwok3030
    @tingkwok3030 3 года назад +11

    really glad I found this. There are so few videos out there that I've found where the code is explained thoroughly and better yet, compared to other ways of achieving the same goal. I was disappointed to find you hadn't made more videos like this!

  • @jlr3636
    @jlr3636 Год назад +1

    Thanks, this is a major jump in my understanding of state machines.
    My project is to take an older Keurig coffee maker, disassemble and separate the parts, then re-assemble into a kind of funky steampunk style coffee maker, using an Arduino to handle the code. Using your code as a starting point, I can add in some temperature, pressure, water level sensors, relays, plus some pumps, and be well on my way of blowing up my house. 😂 thanks

  • @John-ro2yk
    @John-ro2yk 9 месяцев назад

    this was very informative and helpful. I second disappoint in that you've had made a handful of videos. One on structs alone would be worth watching.

  • @CrispyCircuits
    @CrispyCircuits Год назад

    Thank for making this video. My history with both programming and electronics is a bit odd. I learned to program BASIC and some assembly on a Timex-Sinclair 1000. I studied electronics when I was very young, trying to get my ham radio license. I couldn't master the Morse code, so that didn't happen. I also had a surplus military receiver and transmitter that was vacuum tube based.
    Then, lots of time passed. My next programming returned when I started using OpenBSD. Being in that environment is a bit frustrating, but even things barely understood shows the best way for many things. I am also doing electronics again, now. Little pieces from all over the place in time are starting to form into a whole. Thanks again.

  • @beachdancer
    @beachdancer Год назад

    Fascinating. That 3rd method using a struct table was new to me.
    The advantage of pointer over the first switch case seemed partly that you had moved the code into separate functions. Couldn't that also have been done in the first example?
    The problem with my hobby type projects is that I don't know what the states are going to be until some way into the project.

    • @heavybaremetal8682
      @heavybaremetal8682  Год назад +2

      Thanks for the comment. Yes the switch method could just call functions. The table of function pointers method is just an alternative to the switch case, but it can be easier to modify and keep track of.
      Yes dealing with changes is always the hardest part, but making code easy to modify from the start is best. Happy coding!

  • @roncole5789
    @roncole5789 2 года назад

    I created a touchscreen with i2c interface using switch case.

  • @johneagle4384
    @johneagle4384 2 года назад

    I've been exposed to state machines recently, and i've found the subject quite interesting. I have a questions, I am building a little system using Arduino consisting of a GPS, a magnetometer and a lightning sensor.These sensors will be transported by a drone and I will collect the data via a radio link. Does this system benefit from a state machine? Thank you for the video. I love your traffic light!

    • @heavybaremetal8682
      @heavybaremetal8682  2 года назад

      Hi John, thank you for your comment, I'm sorry for the delay in replying. For your system a state machine may not be needed, but I'm not sure. It sounds more like data gathering, so a more suitable design might be to gather the data on a clock tick (similar to how the traffic light system only does something when the next time is reached), then package the data up and send it over your radio link.
      If you continually collect data but only send it say once a second all in one go, then a state machine might be suitable, as there are clearly defined separate states: collect data, send data. But this could also be done just be filling a buffer, then sending once the buffer if full. I hope this helps!

    • @johneagle4384
      @johneagle4384 2 года назад

      @@heavybaremetal8682 Yes, it is data gathering. And I guess I'll follow your advice (filling a buffer). Thank you for the reply!

    • @roncole5789
      @roncole5789 2 года назад

      ​@@heavybaremetal8682 but if you're trained to gather data at and use the data I think a switch case would be better because I did some things a while back and I would crash the CPU. on the Arduino.

  • @roncole5789
    @roncole5789 2 года назад

    I got stoplights on Amazon. I can't wait to sink my teeth into this code.

  • @eswarreddy6280
    @eswarreddy6280 3 года назад

    great one