These are just my thoughts after few years of teaching embedded systems. I am a student myself and I have learned a lot when teaching others.
My philosophy has always been "By following instructions, you learn to follow instructions". So, we designed all exercises to be very simple with "traps". One example is to sample ADC and output the result as a percentage from 0% to 100%. Most students managed to output figures from 0% to 99%.. and then they had to find out why.
My favorite exercise was the "dice" where you had to generate random numbers from 1 to 6. We gave students a hint that there is a library function called "rand()".. haha.. I know, pretty evil
This is what most students wrote first:
I could have won lot of money playing against that code. Every game gave the same sequence of numbers every time.
So.. ~10 lines of code and we had one hour allocated for this one particular exercise. The question was, after the naive approach, how can you make it "more random"?.
The first real "eureka-moment" to students was the realisation of the "while(1)" loop.. and how fast it is.. and it runs "all the time". So, the next version of the program was:
Now the program "throws" the die all the time.. very fast. The moment the user pushes the button catches the current value of the rand(). Good..
But we wanted to push this even further.. do it without the "rand()" -function!
I leave it to you.. Thanks for listening.
My philosophy has always been "By following instructions, you learn to follow instructions". So, we designed all exercises to be very simple with "traps". One example is to sample ADC and output the result as a percentage from 0% to 100%. Most students managed to output figures from 0% to 99%.. and then they had to find out why.
My favorite exercise was the "dice" where you had to generate random numbers from 1 to 6. We gave students a hint that there is a library function called "rand()".. haha.. I know, pretty evil
This is what most students wrote first:
C:
int dice;
while(1)
{
if (button_pressed())
{
dice = rand();
dice = (dice % 6) + 1; /* Limit the range to 1...6 */
display(dice);
}
}
I could have won lot of money playing against that code. Every game gave the same sequence of numbers every time.
So.. ~10 lines of code and we had one hour allocated for this one particular exercise. The question was, after the naive approach, how can you make it "more random"?.
The first real "eureka-moment" to students was the realisation of the "while(1)" loop.. and how fast it is.. and it runs "all the time". So, the next version of the program was:
C:
int dice;
while(1)
{
dice = rand();
if (button_pressed())
{
dice = (dice % 6) + 1; /* Limit the range to 1...6 */
display(dice);
}
}
Now the program "throws" the die all the time.. very fast. The moment the user pushes the button catches the current value of the rand(). Good..
But we wanted to push this even further.. do it without the "rand()" -function!
I leave it to you.. Thanks for listening.
Last edited: