Академический Документы
Профессиональный Документы
Культура Документы
Date : 24/4/2015
Time: 5PM-8PM
Venue: Microcomputer Lab
Click here!
There are two versions of
MIT APP Inventor, which are
MIT APP Inventor1 and
MIT APP Inventor2.
We are using the new version
MIT APP Inventor2.
After you click the App Inventor, you will be directed to
a new page and ask to login in your Gmail account.
Click here!
When completed registration, you will
be directed to the following page.
Now, by using your android phone go Google Play
search for MIT AI2 Companion and install it.
Now, let install for Arduino Software into your
computer.
Click I Agree
Arduino Installation
Click Next
Arduino Installation
Click Install
Final installation step
Reminder:
The Project Name cant has space in between. Only
characters like alphabets, numbers and _ are allowed
Basic Introduction
Project Name
Click here!
Match
Only same pattern edge
can match with one another
First, we will be making an app to
draw a circle.
Click here!
Coordinate system Each primary value of 8 bits with values of 0255 Pixel(Raster Image)
Let Enhance Our App!
Rename Clear_Button
Optional:
1. Create a button to take photo.
2. Set the image as background of canvas.
3. When you are shaking your phone will clear your canvas into a new one and vibrate too.
OR
We will start building our second app (interaction between hardware and
software).
Once you have completed building this app, you will be able to:
1. Understand basic structures and working principles of MIT App Inventor
and Arduino
2. Control Arduino output using Android through Bluetooth
3. Make simple wireless control over LED turning on/off
Arduino + Bluetooth Circuit Connection
This the connection for your Bluetooth to Arduino
void setup()
{
pinMode(ledPin, OUTPUT); // to declare ledPin as output so that arduino can send data to the Pin 6
BT.begin(9600); // set the data rate for the SoftwareSerial port
}
void loop()
{
if (BT.available( )) // if Bluetooth is available
{
number=(BT.read()); // set the byte send from Bluetooth to arduino
if (number==1) // if the number receive is 1 (test condition)
digitalWrite(ledPin, HIGH); // make LED light up
Add a button to the initial app that you have just made, let the button function
as when it click it will call the LED to blinking. You need to add a few lines of
codes in your Arduino program too.
void setup()
{
pinMode(ledPin, OUTPUT); // to declare ledPin as output so that arduino can send data to the Pin 6
BT.begin(9600); // set the data rate for the SoftwareSerial port
}
void loop()
{
if (BT.available( )) // if Bluetooth is available
{
number=(BT.read()); // set the byte send from Bluetooth to arduino
if (number==1) // if the number receive is 1 (test condition)
digitalWrite(ledPin, HIGH); // make LED light up
if (number==2)
{
while(number==2||number==-1){ // while the number receive is 2 or -1 (-1 is due to when android is not sending any data)
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
number=(BT.read()); //always get the number receive to ready to terminate the loop when android send data to this loop
}
}
}
}
Arduino + Android + Bluetooth + Potentiometer
We will start building third app (interaction between hardware and software).
Once you have completed building this app, you will be able to:
1. Understand basic structures and working principles of MIT App Inventor
and Arduino
2. Receive Arduino output using Android through Bluetooth
3. Make simple wireless receiver over getting data from potentiometer
Read data from Arduino then
send to Android
Circuit connection for potentiometer with Arduino
A/D converter
The Arduino has a circuit inside called an analog-to-digital converter that reads
this changing voltage and converts it to a number between 0 and 1023.
Example: 0 V is 0, 3.3V is 678, 5V is 1023
Bluetooth + Arduino + Potentiameter
MIT App
int readPOT = A0; // declare variable name as readPOT and set to pin A1 in arduino (must be a
analog IN port)
int x=0; // declare a variable name as x and set it value to 0
void setup(){
BT.begin(9600); // initialize Bluetooth serial communication
pinMode(readPOT, INPUT); // declare readPOT as input mean to get data from external sensor
or hardware
}
void loop(){
x=analogRead(readPOT); // set the variable x to the value get from readPOT
BT.print(" "); // send a spacing into the android " "
BT.print(x); // send the x data which is also the readPot data to android
delay(1000); // let arduino wait for 1s which also mean stop operation for 1s
}
Another version of doing it
This version is using map function to display the number from 0-255. In this version,
it is receiving Number instead of text. So in Arduino coding, need to use BT.Write
instead of BT.print. (BT.print is for text) & (BT.write is for number)
Arduino Code
#include <SoftwareSerial.h>
SoftwareSerial BT(10,11);
int readPOT = A0; // declare variable name as readPOT and set to pin A1 in arduino (must be a
analog IN port)
int x=0; // declare a variable name as x and set it value to 0
void setup(){
BT.begin(9600); // initialize Bluetooth serial communication
pinMode(readPOT, INPUT); // declare readPOT as input mean to get data from external sensor or
hardware
}
void loop(){
x=analogRead(readPOT); // set the variable x to the value get from readPOT
x = map (x, 0,1023, 0,255); // to change the value of x in range of 0-1023 to 0-255
BT.write(x); // send the x data which is also the readPot data to android
delay(1000); // let arduino wait for 1s which also mean stop operation for 1s
}
Now, we will build our simple game app
We will start building our simple mini game app.
Once you have completed building this app, you will be able to:
1. Understand basic structures and working principles of MIT App Inventor
2. Make simple animated motion
3. Set up nice background and give some decoration to your app
4. Add sound effect
Little things need to know beforehand
Pikachu & Pokeball App
To interchange