Skip to content

Weather display

You need: a computer, a Network Repeater, a Weather Station named sky and a Display Module named screen.

This is the Weather board starter:

starter-weather-board.fsig
// Starter: Weather board (computer)
// Shows the weather on the Display Module "screen" whenever it changes, using the Weather Station "sky".
const sky = weather.named("sky")
const screen = displays.named("screen")
// A function turns a Weather constant into a friendly sentence.
fn describe(now) {
if now is Weather.THUNDER {
return "Storm! Stay inside."
} else if now is Weather.RAIN {
return "It's raining."
}
return "Clear skies."
}
on startup {
screen.write(describe(sky.weather()))
}
on sky.weatherChanged(now, previous) {
screen.write(describe(now))
}
  • describe is a function: it takes a weather constant and gives back a sentence with return. Both handlers use it, so the sentences are written only once.
  • sky.weather() reads the weather right now. At startup the screen shows it immediately.
  • sky.weatherChanged(now, previous) runs when the weather changes. now is the new weather, such as Weather.RAIN.
  • screen.write(...) replaces the text on the screen.

A screen has eight lines. Put the day number on the second line:

const sky = weather.named("sky")
const screen = displays.named("screen")
on sky.dayStart {
screen.setLine(1, "Day " + str(sky.time().day))
}

You can add these handlers to the starter program. setLine(1, ...) changes only the second line, because lines are counted from 0.