coding help for MIT-AI2

I need MIT App Inventor code for a simple alarm clock
Sure! Here's an example of MIT App Inventor code for a simple alarm clock:

  1. First, drag and drop the following components from the Palette to the Viewer:
  • 1 Clock component
  • 1 Button component
  • 1 TimePicker component
  • 1 Sound component
  1. Rename the components as follows:
  • Clock: Clock1
  • Button: Button1
  • TimePicker: TimePicker1
  • Sound: Sound1
  1. Set the properties of the components:
  • Button1: Set the Text property to "Set Alarm"
  • TimePicker1: Set the Visible property to False
  1. Add the following blocks to the Screen's blocks area:

When Button1.Click

Set TimePicker1.Visible to True

When TimePicker1.AfterTimeSet

Set TimePicker1.Visible to False
Set Clock1.TimerEnabled to True

When Clock1.Timer

If Clock1.Hour = TimePicker1.Hour and Clock1.Minute = TimePicker1.Minute then
    Call Sound1.Play
    Set Clock1.TimerEnabled to False
End If

Make sure to add the necessary permissions in the App Inventor Designer view to access the device's clock and sound features.

This code sets up a simple alarm clock functionality. When you click the "Set Alarm" button, the time picker will appear. After you set the desired alarm time, the clock's timer will start running. Once the current time matches the alarm time, the sound component will play and the timer will be disabled.

Feel free to customize the code and add more features according to your requirements.

I just found this interesting.

1 Like

Are you the famous ScottFromScott fron the old Google forum?


I yam

1 Like

Useful tutorial, but will it work in background even after closing the app?

Welcome back! :partying_face:

1 Like

I have not tried that. I think if you leave the app running in the background with the setting 'timer always fires' ticked, it should work. But this is just an example of the state of AI support for MIT App Inventor 2 coding. Like for other languages, the AI can make errors, so don't assume the code is correct.

1 Like