MIT App Inventor: CowBell App
Create an app that plays a cowbell sound!
Open https://ai2.appinventor.mit.edu in your browser. You will need to set up an account to get started.
Create a new project and give it a name -- no spaces or special characters, though.
You should see a screen similar to this with an area to design your app. Follow the instructions below to create and test your app.
- Add a Button
- Drag a Button from User Interface (Palette in far left column) to the phone screen
- Under Properties (far right column), change Text to “Shake the Bell”
- Add Sound
- Drag a Sound component from Media (under Palette on far left) to the phone screen. This is a non-visible component so will display under the phone
- Under Properties (far right column), select Upload File under source. Select the cowbells.ogg file from the desktop.
- Write the Code
- Click the Blocks button (upper right above Properties) to switch to the coding screen
- Under Blocks (far left), select Button1 and drag the [when Button1.Click] block to the center
- Under Blocks, select Sound1 and drag the [call Sound1.Play] block and snap it together with Button1.Click. Your code should look like this:
- Test Your App
- Open the MIT App Inventor Companion app on your
phone or tablet - Select AI Companion from the Connect menu
- Scan the QR code or enter the text code
- Wait while the app connects to your device, then click the button when it’s ready to hear your cowbell ring!
App Enhancements:
- Instead of displaying text on the button, can you display an image of a cowbell? What property would you need to change?
- You can also make the sound play when you shake the phone. To do this, add an AccelerometerSensor (under the Sensors Palette) and then add code for the Shaking event.