Need Help in Timer Component

im sure alot of people are wondering the same question but how do you use timer i want to do a count down timer from 1 hour counting down each seconds in 00:00 time format and once it gets close to last 50 seconds i want it to be red so student feels pressurised its evil but its for their own benefit

You add a ā€œtimerā€ component to your app.

You set it with a ā€œIntervalMillisecond = 1000ā€.
You set it as ā€œenabled= FALSEā€ by default (in the Screen1.starts).
Then you have a Start button that, when clicked, will set ā€œtimer.enabled=TRUEā€, set a global variable to 3600, and set the colour of the label you want to use for display to not red (like labelTimer set color = black ; where black is the appropriate little colour tile in the Color menu in the Blocks mode).

Then, the block ā€œwhen Timer fires doā€ will be called each second (because the timer has been enabled with a 1000 millisecond frequency) and in that block you will, in order,

  • decrement the global variable by one
  • take the value of the now decremented global variable to make a minute / second value (using division, floor and modulo functions) and show that in the timer display
  • check if the global variable is 50 or less, in which case, it changes the colour of the display to red

All you need then may be ancillary buttons like ā€˜pauseā€™ and ā€˜resetā€™ if needed, that will have to fiddle with the timer enabled status, or change the start value, or whatever is needed.

You can have that up and running in less than an hourā€¦

1 Like