Examples
EXAMPLE 1
Bip Bip Bip! Let's create the sound of an alarm. Make the GoGo Board beep five times and wait one second between each time
to beeping
repeat 5 [ beep wait 10 ]
end
Can you make it beep 2 times while waiting 2.5 seconds?
EXAMPLE 2
What about making a light on for specific time? Make the GoGo Boars turn on a light connected to port A for two seconds
to lighton
a, on wait 20 a, off
end
Can you make a traffic light?
Need a hint? Try modifying this code
to trafficlight
a, on wait 20 a, off
b, on wait 20 b, off
end
EXAMPLE 3
Blinking stars. Make the GoGo Board turn a light connected to port A on for two seconds and off for one second a total of five times
to lightonandoff
repeat 5 [a, on wait 20 a , off wait 10]
end
EXAMPLE 4
Make the Gogo tells you when is hot, dark, something is close, or is magnetic. Make the GoGo Board beep whenever a sensor connected to port 1 has a value of less than 500. Try different sensors.
to sensorbeep
forever [
if sensor1 < 500
[beep]
]
end
Can you modify the range (< 500) and make the GoGo Board beep only when is very dark? Or beep when it detects a very close movement?
EXAMPLE 5
Make the GoGo board turn on a light connected to port A and beep whenever a sensor connected to port 1 has a value of less than 500. Otherwise, it should turn light A off. Can you think of when these instructions can be useful?
to sensorbeep
forever [
ifelse sensor1 < 500
[beep b, on]
[b, off]
]
end
EXAMPLE 6
Make the GoGo board turn on a light connected to port A whenever a sensor connected to port 1 has a value of less than 500 and turn the light off if the sensor has a value of 500 or greater. At the same time, make the GoGo board turn on a light connected to port B whenever a sensor connected to port 2 has a value of less than 500 and turn the light off if the sensor has a value of 500 or greater.
to sensorsandlights
forever[
ifelse sensor1 < 500 [a, on] [a, off]
ifelse sensor2 < 500 [b, on] [b, off]
]
end
EXAMPLE 7
Want to collect data? Record the value of a sensor connected to port 1 every second for a minute
to recorddata
resetdp
repeat 60 [ record sensor1 beep wait 10 ]
end
EXAMPLE 8
Make the GoGo board turn on a light connected to port A whenever a sensor connected to port 1 has a value of less than 500 and at the same time a sensor connected to port 2 has a value of more than 500. Otherwise, it should turn the light off.
to useofand
forever [
ifelse (sensor1 < 500 ) and (sensor2 < 500)
[a, on][a, off]
]
end
EXAMPLE 9
Make the GoGo board turn on a light connected to port A either whenever a sensor connected to port 1 has a value of less than 500 or a sensor connected to port 2 has a value of more than 500. Otherwise, it should turn the light off.
to useofor
forever [
ifelse (sensor1 < 500 ) or (sensor2 < 500)
[a, on][a, off]
]
end
EXAMPLE 10
Make the GoGo board count the number of times the value of a sensor connected to port 1 has a value of less than 500. Each time it does so, make the GoGo board beep with the total number of times the sensor has had a value of less than 500 until then.
to example10
make “count 0
forever [
if sensor1 < 500 [
make “count :count + 1
repeat :count [beep wait 5 ]
waituntil [sensor1 > 499]
]
]
end
Bip Bip Bip! Let's create the sound of an alarm. Make the GoGo Board beep five times and wait one second between each time
to beeping
repeat 5 [ beep wait 10 ]
end
Can you make it beep 2 times while waiting 2.5 seconds?
EXAMPLE 2
What about making a light on for specific time? Make the GoGo Boars turn on a light connected to port A for two seconds
to lighton
a, on wait 20 a, off
end
Can you make a traffic light?
Need a hint? Try modifying this code
to trafficlight
a, on wait 20 a, off
b, on wait 20 b, off
end
EXAMPLE 3
Blinking stars. Make the GoGo Board turn a light connected to port A on for two seconds and off for one second a total of five times
to lightonandoff
repeat 5 [a, on wait 20 a , off wait 10]
end
EXAMPLE 4
Make the Gogo tells you when is hot, dark, something is close, or is magnetic. Make the GoGo Board beep whenever a sensor connected to port 1 has a value of less than 500. Try different sensors.
to sensorbeep
forever [
if sensor1 < 500
[beep]
]
end
Can you modify the range (< 500) and make the GoGo Board beep only when is very dark? Or beep when it detects a very close movement?
EXAMPLE 5
Make the GoGo board turn on a light connected to port A and beep whenever a sensor connected to port 1 has a value of less than 500. Otherwise, it should turn light A off. Can you think of when these instructions can be useful?
to sensorbeep
forever [
ifelse sensor1 < 500
[beep b, on]
[b, off]
]
end
EXAMPLE 6
Make the GoGo board turn on a light connected to port A whenever a sensor connected to port 1 has a value of less than 500 and turn the light off if the sensor has a value of 500 or greater. At the same time, make the GoGo board turn on a light connected to port B whenever a sensor connected to port 2 has a value of less than 500 and turn the light off if the sensor has a value of 500 or greater.
to sensorsandlights
forever[
ifelse sensor1 < 500 [a, on] [a, off]
ifelse sensor2 < 500 [b, on] [b, off]
]
end
EXAMPLE 7
Want to collect data? Record the value of a sensor connected to port 1 every second for a minute
to recorddata
resetdp
repeat 60 [ record sensor1 beep wait 10 ]
end
EXAMPLE 8
Make the GoGo board turn on a light connected to port A whenever a sensor connected to port 1 has a value of less than 500 and at the same time a sensor connected to port 2 has a value of more than 500. Otherwise, it should turn the light off.
to useofand
forever [
ifelse (sensor1 < 500 ) and (sensor2 < 500)
[a, on][a, off]
]
end
EXAMPLE 9
Make the GoGo board turn on a light connected to port A either whenever a sensor connected to port 1 has a value of less than 500 or a sensor connected to port 2 has a value of more than 500. Otherwise, it should turn the light off.
to useofor
forever [
ifelse (sensor1 < 500 ) or (sensor2 < 500)
[a, on][a, off]
]
end
EXAMPLE 10
Make the GoGo board count the number of times the value of a sensor connected to port 1 has a value of less than 500. Each time it does so, make the GoGo board beep with the total number of times the sensor has had a value of less than 500 until then.
to example10
make “count 0
forever [
if sensor1 < 500 [
make “count :count + 1
repeat :count [beep wait 5 ]
waituntil [sensor1 > 499]
]
]
end