We started out with a review. I even made an Impres presentation (that's the Open Office version of Power Point.) We reviewed the basic symbols in a schematic that we would use in today's project. Next, we went over the LED, it's properties, and how to determine the anode (+) and cathode (-) side. And, finally, we reviewed the code they would need for the project. This included integer variables, the setup() and loop() functions, analogWrite, pinMode, and a very long discussion about for loops and nested for loops. This eventually, somehow, got into a long discussion about bits and bytes. Now they know how to count in binary. lol!
Next, the kids built their circuit, taking turns installing and wiring 3 LEDs on the mini breadboard and connecting them to the Arduino. They connected the anodes to pins 1, 3, and 5 and the cathodes to pins 2, 4, and 6.
Finally, they wrote the code. The 7 year old wrote the initial comments and the setup() function and the 11 year old wrote the loop(). Debugging was a hoot. They quickly found out that this is case sensitive since it didn't even like the "VOID" before the setup() function.
Their assignment was to turn on and turn off all 3 LEDs in any manor they chose.
They decided to light LED3, pause 1 second, light LED2, pause 1 second, light LED3, and pause 1 second. Then fade LED3 off, LED2 off, and LED1 off. I was impressed with a few things.
- My son (the 7 year old) really grasped the concept of variables, because when he wrote his loop in the setup, he chose to create a variable called "code" instead of "pin." This, to me, meant that he really understood that the variable was just a holding place with a name and whatever he chose to name it had no bearing on the program.
- My daughter chose to fade out the LEDs. This required her to create a nested loop, making this a much more complex first sketch. Good to know she wasn't afraid to put everything she learned into practice.
Here's what they came up with:
//LED1=+1 -2 //LED2=+3 -4 //LED3=+5 -6 void setup(){ for(int code=1;code<7;code++){ pinMode(code,OUTPUT); } } void loop(){ for(int led =5;led>=1;led=led-2){ analogWrite(led,255); delay(1000); } for(int led =5;led>=1;led=led-2){ for(int code=255;code>=0;code--){ analogWrite(led,code); delay(10); } } }
No comments:
Post a Comment