Training Master Students
Once upon a time.
I, the mighty master student, was granted the privilege to train two other master students and mold them in my image. This was a clever plan created by the two research lords who worked compiler magic to generate new programing languages for the working man to enjoy.
Having two apprentices when you are just a master student sound like a great deal of responsibility, and I, the mighty master student, can agree on that. In fact it is almost to much responsibility, but luckily for me they are for the most part obedient, at least if it is not on a day where a horde of web comics are released, if that is the case Kyrre is lost in the depth of the all-knowing interwebz.
The master plan of the research lords are to provide the general public with a programing language that the simplest peasant can program as if he was the king of programmers. This new glorious programming language are called ThingML and is supposed to be able to
program
all the things
One of the visions the research lords have is that everything that is programmed should be able to access the all-knowing interwebz, and since the interwebz is in fact all-knowing all things that are interlaced with the interwebz could also be all-knowing. Imagine the wast amount of things that would know everything. Your toaster could know what the weather is, your fridge could know today’s quests, your electric toothbrush could know your kill count and the TV schedule and your computer could know how often you brush your teeth, how often you open your fridge and how often opening the fridge results in a toast.
This is a vision well shared with the mighty master student, and a vision that I, the mighty master student, are trying to push down on my apprentices.
To get my apprentices to fully grasp this great heaven like idea I must train them like only a mighty master student can do, and I believe that the best way to train is to head out to life threatening programing quests that could fail miserably or bring home gold and fortune to your fellow programmers.
This day I sent my young students on a very dangerous quest, and I must admit that I was not expecting either of them to complete this task by the end of this day, but in fact they both manage to shine through and prove them self very special. The quest the mighty master student gave them on this glorious day was to make a potentiometer of doom to control the timer interrupts of great descending and ultimately control the rate of which a mystical LED is blinking. This was not a trivial quest, one might thing so, but only if one have yet to try out the magnificent language of ThingML. It is a state machine oriented language that requires you to program the potentiometer of doom in one realm and the mystical LED in a whole another realm. This I did not know in my youth and had to learn the hard way, by trial and error and then directly from the research lords. My apprentices on the other hand got this knowledge as a hint in the quest description.
You might also wonder how the apprentices solved this quest, and I will tell you that great tale. They used the simplest of logic, they avoided all bloathiness by dodging all dangerous obstacles through learning and exploring of all great things in the land of ThingML. They traversed files and found hidden messages that could travel through enchanted ports and trigger old mythological states to act on newly discovered input from the potentiometer of doom. They did well and earned them self a great loot of XP and wisdom.
In fact they did better then their almigty teacher and earned more xp then I did on that spesific quest in my youth. Not only did the both manage to finnish the quest with a lower linecount, but also by using fewer enchanted ports and hidden messages.
But in order to show you, the reader of this tale, that I am not a noob, but still better then my two young padawans, my code had the great ability to cancel out any timer events on the LED and restart it when needed, theirs code could not.
Here you can see Kyrres code
import "../../hardware/bricks/led.thingml"
import "../../hardware/io/analog_input.thingml"
thing portRGB includes TimerMsgs, LedMsgs, AnalogInputMsgs {
property temp : UInt16 = 100
required port timer {
receives timer_timeout
sends timer_start, timer_cancel
}
required port led {
sends led_on, led_off, led_toggle
}
required port input {
receives analog_input_value
sends read_analog_input
}
statechart portRGBImpl init green {
state Led {
on entry do
timer!timer_start (temp)
end
transition->Led
event timer?timer_timeout
}
region potMeter init pot {
state pot {
on entry do
input!read_analog_input ()
end
transition->pot
event m: input?analog_input_value
action do
if(m.value > 1) do
temp = m.value
end
end
}
}
}
}
And here comes the code that I, the almighty master student, wrote in my youth:
import "../../hardware/io/analog_input.thingml"
import "../../hardware/bricks/led.thingml"
thing AnalogReadBlink includes AnalogInputMsgs, TimerMsgs, LedMsgs{
property freq : UInt16 = 0
required port TimerPot
{
sends timer_start
receives timer_timeout
}
required port TimerLed
{
sends timer_start
sends timer_cancel
receives timer_timeout
}
required port Led
{
sends led_toggle
}
required port AnalogInput
{
sends read_analog_input
receives analog_input_value
}
message update();
provided port ReceiveUpdate
{
receives update
}
required port SendsUpdate
{
sends update
}
statechart AnalogReadBlinkImpl init ReadPot
{
property delay : UInt16 = 100
state ReadPot
{
on entry do
AnalogInput!read_analog_input()
TimerPot!timer_start(20)
end
internal event m : AnalogInput?analog_input_value
action do
if( not (delay == m.value)) do
if( not (m.value == 0)) do
if (m.value < delay - 3 or m.value > delay + 3) do
delay = m.value
SendsUpdate!update()
'Serial.println('& m.value &');'
end
end
end
end
transition -> ReadPot
event TimerPot?timer_timeout
}
region Led init Blink
{
state Blink
{
on entry do
Led!led_toggle()
TimerLed!timer_start(delay)
end
transition ->Blink
event TimerLed?timer_timeout
transition -> Blink
event ReceiveUpdate?update
action TimerLed!timer_cancel()
}
}
}

This site uses valid HTML and CSS. All content Copyright © 2010 Newscast, Inc
If you like what we do, please don't hestitate and subscribe to our
[...] Enjoy! [...]