Group Assignment
Google says that "A GUI displays objects that convey information, and represent actions that can be taken by the user. The objects change color, size, or visibility when the user interacts with them". I thought that if I tried to convey info, represent actions, and change the properties of the objects I would have mastered the basics of the tools that I was going to use.
I decided to build a simple stopwatch using both VB.NET and App Inventor. A simple stopwatch contains
First I tried using Visual Studio to design and program my GUI.
To create a GUI for windows you need to select Windows Forms App
Building a GUI in Visual Studio was pretty simple; just drag and drop the elements from the Toolbox on the left, then change each Item properties from the Properties panel on the bottom right of the screen.
There is an element called Timer which is basically needed to give the sense of time to the application, because it can be linked to a function that can be executed each time the timer interval is reached. I set the interval for the timer to be 1000ms in order to have my code executed each second.
After finishing the design, I went to write the basic code for the buttons and the timer.
The code is straightforward:
I ran the code and the application worked well.
The second trial would be in App Inventor. I created the roughly the same GUI using the same element; except for the name of the Timer element was named Clock in App Inventor.
I implemented the same previous algorithm but using blocks this time.
In order to test the code in App Inventor, I had to install the Android Emulator.
After that the application ran nicely.
Preparing the Board
#define btn 7
#define led 8
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // RX, TX
bool pressed = false;
void setup() {
pinMode(btn, INPUT_PULLUP);
pinMode(led, OUTPUT);
mySerial.begin(9600);
}
void loop() {
if (digitalRead(btn) == LOW && pressed == false)
{
pressed = true;
mySerial.write(byte(0x01));
delay(100); // debouncing
}
if (digitalRead(btn) == HIGH && pressed == true)
{
pressed = false;
mySerial.write(byte(0x02));
}
if (mySerial.available())
{
byte msg = mySerial.read();
if (msg == 0x0A) digitalWrite(led, HIGH);
if (msg == 0x0B) digitalWrite(led, LOW);
}
}
Processing Interface
import processing.serial.*;
Serial mySerial;
color value = color(255, 255, 255);
boolean pressed = false;
void setup() {
surface.setTitle("Test I/O");
size(500, 500);
mySerial = new Serial(this, Serial.list()[0], 9600);
}
void draw() {
background(0);
if (mySerial.available()>0)
{
byte msg = mySerial.readBytes(1)[0];
if (msg == 0x01) value = color(0, 0, 255);;
if (msg == 0x02) value = color(255, 255, 255);;
}
fill(value);
rect(125, 125, 250, 250);
}
void mousePressed() {
if (mouseX>125 && mouseX <375 && mouseY>125 && mouseY<375 )
{
pressed = true;
value = color(0, 255, 0);
mySerial.write(byte(0x0A));
}
}
void mouseReleased() {
if (pressed)
{
pressed = false;
value = color(255, 255, 255);
mySerial.write(byte(0x0B));
}
}
Python Interface
pip install -U selenium
I then got those lines from the web examples. They simply do the following:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import time
def createWebDriver(browserNumber):
if browserNumber == 0: return webdriver.Firefox() # FireFox
elif browserNumber == 1: return webdriver.Chrome() # Chrome
driver = createWebDriver(1)
actions = ActionChains(driver)
driver.get('http://www.trex-game.skipser.com/')
while True:
actions.send_keys(Keys.SPACE).perform()
time.sleep(1.5)
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import serial
port = 'COM22'
def createWebDriver(browserNumber):
if browserNumber == 0: return webdriver.Firefox() # FireFox
elif browserNumber == 1: return webdriver.Chrome() # Chrome
driver = createWebDriver(1)
actions = ActionChains(driver)
driver.get('http://www.trex-game.skipser.com/')
monitor = serial.Serial(port,9600,timeout=5)
monitor.flush()
monitor.flushInput()
while True:
data = monitor.read()
if (data== bytes(b'\x01')):
monitor.write(bytes(b'\x0A'))
actions.send_keys(Keys.SPACE).perform()
monitor.write(bytes(b'\x0B'))
monitor.flush()
monitor.flushInput()
Downloads