Hey there,
My first post, I'm actually trying to learn C++ myself and I thought I'd challenge myself a little, and I think this is a good exercise for anybody else trying to learn.
First of all, just wanted to say how cool this community is. I'm actually a sales guy by trade, but I run my own company now and I saw the potential for Arduino in introducing non-tech professionals into learning tech. So thank you for everything that Arduino and you guys in the community have provided for newbies like me to learn!
Second, any newbies out there, if you're looking to learn C++ (the programming language of Arduino), I'm using an Ipad app called Learn C++ Pro. Its in the app store and is full of video examples, exercises, and a cool little roadmap you travel down on the way to your certificate. These guys also have solo-learn courses for Java, PHP, HTML, CSS and a bunch of other languages too for any of you experts out there who are looking to dig into another language. Awesome resource!
The Exercise: Under the Examples selection on the Learning tab, scroll down to 5. Controls and do the Switch Case 2 exercise. Do the exercise as written to make sure you understand, I think it helps to type out the code yourself rather than just copying and pasting, kind of forces you to look at every single element in the code as you type.
Here's the twist, when you do the exercise you'll notice that when you enter 'a' 'b' 'c' 'd' or 'e' into the serial monitor to turn on the lights, if you type in one of the other letters, another corresponding light to that letter will light up, but the previous light stays on as well.
So here's the challenge:
How would you write this code so that after you turn on one light, whenever you type another letter corresponding to one of the other lights, it also turns off the previous light, so that you can only have one light lit at a time?
I attached my variation of the sketch, but try not to look at it! Think it through, I had to try a couple times during the day and I couldn't figure it out until I walked away and came back to it later at night.
Switch_Case_2_Variation.ino (1.2 KB)