Sten-SLATE ESP. Graphical Interface

Similar documents
Building a GUI From Scratch

Sten-SLATE ESP. WiFi

CISC 1600, Lab 2.2: Interactivity in Processing

CISC 1600, Lab 3.2: Interactivity in Processing

Parts List. XBEE/Wifi Adapter board 4 standoffs ¼ inch screws Cable XBEE module or Wifi module

Introduction to Processing

Parts List. XBEE/Wifi Adapter board 4 standoffs ¼ inch screws Cable XBEE module or Wifi module

Interaction Design A.A. 2017/2018

Conditional Events. Mouse events and Operators. Dr. Siobhán Drohan Mairead Meagher. Produced by:

Using Methods. Methods that handle events. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

CISC 1600 Lecture 2.2 Interactivity&animation in Processing

CISC 1600 Lecture 2.2 Interactivity&animation in Processing

CISC 1600, Lab 3.1: Processing

CISC 1600, Lab 2.1: Processing

mith College Computer Science CSC103 How Computers Work Week 6 Fall 2017 Dominique Thiébaut

Exploring Processing

The way I feel about music is that there is no right and wrong. Only true and false. Fiona Apple. true false false

Real Time Data Plotting

Variables and Control Structures. CS 110 Eric Eaton

Sten-SLATE ESP Kit. Description and Programming

Introduction to Processing. Sally Kong

Methods (cont.) Chapter 7

GRAPHICS PROGRAMMING. LAB #3 Starting a Simple Vector Animation

Kimberly Nguyen Professor Oliehoek Introduction to Programming 8 September 2013

Basic Computer Programming (Processing)

Pick a number. Conditionals. Boolean Logic Relational Expressions Logical Operators Numerical Representation Binary. CS Conditionals 1

mith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut

1 Getting started with Processing

CISC 1600 Lecture 3.1 Introduction to Processing

What can we do with Processing? Let s check. Natural Language and Dialogue Systems Lab Guest Image. Remember how colors work.

Basic Input and Output

CST112 Looping Statements Page 1

Computer Graphics. Interaction

A B C D CS105 03a Interaction

Sten-SLATE ESP. Simple Web Server

[ the academy_of_code] Senior Beginners

Advanced Activities - Information and Ideas

Module 01 Processing Recap. CS 106 Winter 2018

University of Cincinnati. P5.JS: Getting Started. p5.js

Basic Input and Output

The Processing language

Watch the following for more announcements

Connecting Arduino to Processing

Basic Input and Output

Final Exam Winter 2013

Bits and Bytes. How do computers compute?

StenBOT Robot Kit. Stensat Group LLC, Copyright 2018

CMPT-166: Sample Midterm

COMP Summer 2015 (A01) Jim (James) Young jimyoung.ca

Module 05 User Interfaces. CS 106 Winter 2018

Basic Input and Output

Question 1 (10 points) Write the correct answer in each of the following: a) Write a Processing command to create a canvas of 400x300 pixels:

The Processing language. Arduino and Processing.

if / if else statements

cs6964 March TOOLKITS Miriah Meyer University of Utah

Name CMPS 5J Final March 17, 2010 This is a closed notes, closed book exam. Each problem is worth 1 point unless indicated otherwise.

Recall that creating or declaring a variable can be done as follows:

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

COMP Summer 2015 (A01) Jim (James) Young jimyoung.ca

Chapter 12: Functions Returning Booleans and Collision Detection

We will start our journey into Processing with creating static images using commands available in Processing:

Arduino for ODROID-GO - Hello World

CS110 Introduction to Computing Fall 2016 Practice Exam 1

CSE120 Wi18 Final Review

5.1. Examples: Going beyond Sequence

University of Portland EE 271 Electrical Circuits Laboratory. Experiment: Arduino

What is a variable? a named location in the computer s memory. mousex mousey. width height. fontcolor. username

Windows and Events. created originally by Brian Bailey

All program statements you write should be syntactically correct. Partial credit is not guaranteed with incorrect use of syntax.

Class Notes CN19 Class PImage Page

CS 101 Functions. Lecture 15

CS 101 Media (Images, Video, etc) Lecture 20

CS110 Introduction to Computing Fall 2016 Practice Exam 1 -- Solutions

void setup() { void draw() { draw a rectangle or ellipse wherever the mouse cursor is }

Interaction Design A.A. 2017/2018

Repetition is the reality and the seriousness of life. Soren Kierkegaard

Sten-SLATE ESP. Accelerometer and I2C Bus

Module 01 Processing Recap

What is a variable? A named locajon in the computer s memory. A variable stores values

Touch Board User Guide. Introduction

Variables One More (but not the last) Time with feeling

Getting Started with Processing by Casey Reas and Ben Fry

(Inter)Ac*ve Scripts. Sta*c Program Structure 1/26/15. Crea+ve Coding & Genera+ve Art in Processing 2 Ira Greenberg, Dianna Xu, Deepak Kumar

EP486 Microcontroller Applications

PROJECT FINAL: WEARABLE

CS 106A, Lecture 14 Events and Instance Variables

Processing Assignment Write- Ups

Sten-SLATE ESP. Introduction and Assembly

void mouseclicked() { // Called when the mouse is pressed and released // at the same mouse position }

Procedure: Determine the polarity of the LED. Use the following image to help:

COMP Summer 2015 (A01) Jim (James) Young jimyoung.ca

CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM

CS 106 Winter Lab 03: Input and Output

Solution Notes. COMP 151: Terms Test

CSC 220 Object-Oriented Multimedia Programming, Spring 2017

Processing. Data Visualization Programming Language. By Rutvi Joshi. Processing Visualization Language- By Rutvi Joshi

CS 106A, Lecture 14 Events and Instance Variables

Event-driven Programming: GUIs

Interaction Design A.A. 2017/2018

PROGRAMMING. We create identity

Transcription:

Sten-SLATE ESP Graphical Interface Stensat Group LLC, Copyright 2016 1

References www.arduino.cc http://esp8266.github.io/arduino/versions/2.1.0/doc/reference.html 2

Graphical Interface In this section, you will learn how to build a simple graphical user interface. Keep the circuit and arduino code as is. It will be used in this section. Two buttons will be created to control the two LEDs. A new prorgram will be created in Processing. Open a new window in Processing. 3

Importing Libraries Start the Processing software. Click on the Sketch menu and select the Import Library import processing.network.*; Select the network library. The import command will appear at the top of the editor. This tells the compiler to include the library of functions to support network operations. This library will be used to access the processor over wifi. 4

Setting up a TCP Port The next step is to create a network object that will provide access to the wifi. The variables button1_pressed and button2_pressed are created. These will be used to indicate that the button was already pressed. The draw() function is executed repeatedly so the checks for the buttons being pressed will be true and the commands will be sent repeatedly. import processing.network.*; Client c; int button1_pressed,button2_pressed; 5

setup() In the setup() function, the network object is configured to talk to the robot at the IP address of 192.168.4.1 using port 80. A window of 800 by 600 pixels is also created. The variables are set to zero to indicate the buttons are not pressed. import processing.network.*; Client c; int button1_pressed,button2_pressed; void setup() { size(800,600); c = new Client(this, 192.168.4.1,80); button1_pressed = 0; button2_pressed = 0; This completes the setup() portion of the code. Next is the draw() function. 6

setup() A label will be created for each button. To prepare for the text, the function textalign() tells the program to center the text around the coordinates specified in the text() function otherwise the text will start at the coordinates and be shifted to the right. textsize() sets the font size. import processing.network.*; Client c; int button1_pressed,button2_pressed; void setup() { size(800,600); c = new Client(this, 192.168.4.1,80); button1_pressed = 0; button2_pressed = 0; textalign(center); textsize(18); 7

Rendering the Buttons The draw() function does all the work. First, the window is cleared with the background() function and the buttons are rendered in their proper state. If a button is not pressed, it is gray. If the button is pressed, it is the color of the LED. void draw() { background(0); // black window if(button1_pressed == 0) fill(200); // set button gray else fill(100,0,0); rect(100,100,100,100,10); if(button2_pressed == 0) fill(200); else fill(0,100,0); rect(250,100,100,100,10); 8

Rendering the Buttons The text is rendered after the buttons are created. The order of operation is important. Any graphic created will be rendered on top of previous graphics. The text is rendered on top of the rectangles so the text() function needs to come after the rect() function. void draw() { background(0); // black window if(button1_pressed == 0) fill(200); // set button gray else fill(100,0,0); rect(100,100,100,100,10); if(button2_pressed == 0) fill(200); else fill(0,100,0); rect(250,100,100,100,10); fill(0); text( GREEN,300,155); text( RED,150,155); fill(0) sets the color of the text to black. The text() function renders the text at the specified coordinates. 9

User Interaction After rendering the buttons, it is time to check on the state of the buttons. The first check is if the mouse button is pressed. If true, the variable mousepressed will not be zero. void draw() { background(0); // black window if(button1_pressed == 0) fill(200); // set button gray else fill(100,0,0); rect(100,100,100,100,10); if(button2_pressed == 0) fill(200); else fill(0,100,0); rect(250,100,100,100,10); fill(0); text( GREEN,300,155); text( RED,150,155); if(mousepressed) { if((mousex > 100) && (mousex < 200)) { if((mousey > 100) && (mousey < 200)) { if(button1_pressed == 0) { c.write( F ); button1_pressed = 1; 10

User Interaction To determine which button if any is pressed, a simple boundary check of where the mouse position is in relation to the rectangles used for buttons is performed. First the x dimension is checked. Notice the &&. This means AND. This requires both comparisons to be true for the if() statement to be true. void draw() { background(0); // black window if(button1_pressed == 0) fill(200); // set button gray else fill(100,0,0); rect(100,100,100,100,10); if(button2_pressed == 0) fill(200); else fill(0,100,0); rect(250,100,100,100,10); fill(0); text( GREEN,300,155); text( RED,150,155); if(mousepressed) { if((mousex > 100) && (mousex < 200)) { if((mousey > 100) && (mousey < 200)) { if(button1_pressed == 0) { c.write( F ); button1_pressed = 1; 11

User Interaction Next, the button1_pressed variable is checked to see if it has been changed from zero. If it is zero, the command to turn on the red LED is sent and the variable is changed to 1. This is done so that next time draw() is executed and the button is still pressed, the command will not be sent again. void draw() { background(0); // black window if(button1_pressed == 0) fill(200); // set button gray else fill(100,0,0); rect(100,100,100,100,10); if(button2_pressed == 0) fill(200); else fill(0,100,0); rect(250,100,100,100,10); fill(0); text( GREEN,300,155); text( RED,150,155); if(mousepressed) { if((mousex > 100) && (mousex < 200)) { if((mousey > 100) && (mousey < 200)) { if(button1_pressed == 0) { c.write( F ); button1_pressed = 1; 12

User Interaction The second button is checked and processed like the first button. Only the X position is different and of course a different command is sent. rect(250,100,100,100,10); fill(0); text( GREEN,300,155); text( RED,150,155); if(mousepressed) { if((mousex > 100) && (mousex < 200)) { if((mousey > 100) && (mousey < 200)) { if(button1_pressed == 0) { c.write( F ); button1_pressed = 1; if((mousex > 250) && (mousex < 350)) { if((mousey > 100) && (mousey < 200)) { if(button2_pressed == 0) { c.write( L ); button2_pressed = 1; 13

User Interaction Now when the mouse button is not pressed, any buttons on the screen that was clicked on needs to be changed to the unpressed state. Variable button1_pressed is checked to see if it was a pressed button. The command to turn the LED off is sent and the variable is reset. Same thing happens to the second button. if((mousex > 250) && (mousex < 350)) { if((mousey > 100) && (mousey < 100)) { if(button2_pressed == 0) { c.write( L ); button2_pressed = 1; else { if(button1_pressed == 1) { c.write( B ); button1_pressed = 0; if(button2_pressed == 1) { c.write( S ); button2_pressed = 0; 14

Test Add a third LED to the processor board and update its software to accept commands to turn it on and off. Modify the processing program to add a third button to turn the third LED on and off. 15