Wait
Syntax:
control.wait(1)
Example:
led.flashCmd
control.wait(1)
led.colourWordCmd('red')
control.wait(1)
led.colourWordCmd('green')
control.wait(1)
led.colourWordCmd('blue')
control.wait(1)
led.offCmd()
For Loop
Syntax:
for (counter = 1; counter < 10; counter++) {
//your code
}
Example:
led.flashCmd()
for (pix = 1; pix < 10; pix++) {
led.pixel(pix).colourWordCmd('red')
control.wait(0.25)
}
for (pix = 1; pix < 10; pix++) {
led.pixel(10-pix).colourWordCmd('blue')
control.wait(0.25)
}
led.flashCmd()
Repeat Until
Syntax:
control.repeatUntil(function() {
return //your condition
}, function() {
//your code
})
Example:
control.repeatUntil(function() {
return eBot.sensors.button //this is the condition that needs to be true
}, function() { //this is the code that repeats
led.flashCmd()
console.log('repeating until button is pressed')
control.wait(0.3)
})
console.log('Button is pressed so we exit') //note that repeatUntil is blocking so this line executes after exit from repeatUntil
Repeat
Syntax:
control.repeat(10) {
/* your code */
}
Example:
control.repeat(5, function() {
led.flashCmd()
control.wait(0.25)
})
Forever
Syntax:
control.forever(function () {
/* your code */
})
Example:
control.forever(function() {
led.flashCmd()
control.wait(0.25)
})
If Then
Syntax:
if (yourCondition) {/* your code */}
Example:
control.forever(function(){
if (eBot.sensors.line.analog.LHS > 50) {
console.log('I see white')
}
if (eBot.sensors.line.digital.LHSBlack) {
console.log('I see black')
}
})
If Then Else
Syntax:
if (yourCondition) {
/* your code */
} else {
/* your code */
}
Example:
control.forever(function(){
if (eBot.sensors.line.analog.LHS > 50) {
console.log('I see white')
} else {
console.log('I do not see white')
}
})
Wait Until
Syntax:
control.waitUntil(function(){
return your condition;
})
Example:
console.log('start the code')
control.waitUntil(function(){
return eBot.sensors.button //this is the condition that needs to be true
})
console.log('the button has been pressed and the wait until has exited')
Stop All
Syntax:
control.stopAll()
Example:
control.forever(function(){
if (eBot.sensors.button) {
console.log('the button was just pressed so all code will stop')
control.stopAll() //stop ALL code running - note this is not a wheels stop command
}
console.log('we are still in a loop')
})