tag:blogger.com,1999:blog-64277710805615529502024-03-04T21:22:50.896-08:00Sam's Neat Project Blog CODEUnknownnoreply@blogger.comBlogger15125tag:blogger.com,1999:blog-6427771080561552950.post-18175768027127690452017-08-15T13:38:00.001-07:002017-11-06T14:54:10.064-08:00Update RTC//CODE BY SAM BASKIN HIES 2018<br />
//If you're trying to figure this out and I'm graduated then don't hesitate to email me at samsonbaskin@gmail.com or call 404-680-1281<br />
<br />
<br />
#include <Wire.h><br />
#include "RTClib.h"<br />
#include <Servo.h><br />
RTC_DS1307 RTC;<br />
int yearLast = 17;<br />
int daysOfWeek;<br />
int wait1 = 200;<br />
int daylightSavings = 0; //0 if between November and March, 1 if between March and November<br />
int wait2 = 500;<br />
float w = 0;<br />
int sCount = 0;<br />
int tune = 0;<br />
Servo remus;<br />
Servo spin;<br />
int monthCode[12] = {1, 4, 4, 0, 2, 5, 0, 3, 6, 1, 4, 6};<br />
//char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};<br />
<br />
<br />
void setup () {<br />
pinMode(A2, OUTPUT);<br />
digitalWrite(A2, LOW);<br />
pinMode(A3, OUTPUT);<br />
digitalWrite(A3, HIGH);<br />
Serial.begin(9600);<br />
Wire.begin();<br />
RTC.begin();<br />
remus.attach(9);<br />
<br />
//remus.attach(9);<br />
remus.write(100);<br />
delay(500);<br />
remus.detach();<br />
//char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};<br />
<br />
<br />
//IMPORTANT: INSTRUCTIONS FOR RESETTNG TIME AND ADJUSTING FOR DAYLIGHT SAVINGS<br />
//If it just went between daylight savings or not daylight savings, you can also follow the below instructions.<br />
//STEP 1: Uncomment the line below to reset time.<br />
//STEP 2: After uploading, re-comment the line and upload again.<br />
//Otherwise the time will reset every time you start the sketch.<br />
// RTC.adjust(DateTime(__DATE__, __TIME__)); <br />
//^^^^^^^^^^THIS IS THE LINE YOU SHOULD COMMENT/UNCOMMENT(like the one above this line, not THIS line. You troll.)^^^^^^^^<br />
<br />
<br />
<br />
if (! RTC.isrunning()) {<br />
Serial.println("RTC is NOT running!");<br />
// following line sets the RTC to the date & time this sketch was compiled<br />
<br />
<br />
//Allows for precise time setting<br />
// RTC.setHours(15);<br />
// RTC.setMinutes(7);<br />
// RTC.setSeconds(5)<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
<br />
void loop () {<br />
<br />
printTime1(); //Calls printTime1 method to prints timestamp<br />
<br />
<br />
/*<br />
* SET BELL TIMES HERE<br />
*/<br />
//CHECK TIME SECTION<br />
//Use -1 as an input if you want any hour<br />
//FORMAT: checkTime(hour, minute, second). ring(How many times you want it to ring)<br />
//No need for "== true" because checkTime is a boolean method<br />
<br />
//IF NOT THURS<br />
<br />
if (daysOfWeek != 5 && daysOfWeek != 1 && daysOfWeek != 7)<br />
{<br />
if (checkTime(8, 29, 45))<br />
{<br />
ring(1);<br />
}<br />
if (checkTime(9, 39, 45))<br />
{<br />
ring(1);<br />
}<br />
if (checkTime(9, 44, 45))<br />
{<br />
ring(1);<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
if (daysOfWeek == 5)<br />
{<br />
if (checkTime(8, 19, 45))<br />
{<br />
ring(1);<br />
}<br />
if (checkTime(9, 29, 45))<br />
{<br />
ring(1);<br />
}<br />
if (checkTime(9, 29, 45))<br />
{<br />
ring(1);<br />
}<br />
}<br />
<br />
<br />
//STANDARD DAY<br />
if (daysOfWeek != 7 && daysOfWeek != 1)<br />
{<br />
<br />
if (checkTime(10, 24, 45))<br />
{<br />
ring(1);<br />
}<br />
if (checkTime(10, 29, 45))<br />
{<br />
ring(1);<br />
}<br />
if (checkTime(11, 39, 45))<br />
{<br />
ring(1);<br />
}<br />
if (checkTime(11, 44, 45))<br />
{<br />
ring(1);<br />
}<br />
if (checkTime(12, 54, 45))<br />
{<br />
ring(1);<br />
}<br />
if (checkTime(13, 44, 45))<br />
{<br />
ring(1);<br />
}<br />
if (checkTime(14, 59, 45))<br />
{<br />
ring(1);<br />
}<br />
if (checkTime(16, 59, 45))<br />
{<br />
ring(1);<br />
}<br />
<br />
<br />
}<br />
<br />
//ROBOTICS STUFF<br />
if (daysOfWeek == 5 || daysOfWeek == 3)<br />
{<br />
if (checkTime(15, 14, 45))<br />
{<br />
ring(1);<br />
}<br />
if (checkTime(16, 49, 45))<br />
{<br />
ring(1);<br />
}<br />
}<br />
<br />
if(Serial.available() > sCount)<br />
{<br />
ring(1);<br />
sCount++;<br />
}<br />
<br />
<br />
<br />
<br />
<br />
delay(1000);<br />
}<br />
<br />
<br />
<br />
<br />
<br />
//CONTROLS SERVO TO RING BELL<br />
void ring(int n)<br />
{<br />
for (int i = 0; i < n; i++)<br />
{<br />
remus.attach(9);<br />
delay(500);<br />
remus.write(140);<br />
delay(600);<br />
remus.write(100);<br />
delay(500);<br />
remus.detach();<br />
}<br />
}<br />
<br />
<br />
//PRINTS TIME<br />
void printTime1()<br />
{<br />
//int daysOfWeek<br />
DateTime now = RTC.now();<br />
int dayOWeek = int(yearLast / 4) + now.day() + monthCode[now.month()-1] + 6 + 17;<br />
if (now.month() == 1 || now.month() == 2)<br />
{<br />
daysOfWeek = (dayOWeek % 7) + 1;<br />
}<br />
else<br />
{<br />
daysOfWeek = dayOWeek % 7;<br />
}<br />
<br />
<br />
Serial.print(now.year(), DEC);<br />
Serial.print('/');<br />
Serial.print(now.month(), DEC);<br />
Serial.print('/');<br />
Serial.print(now.day(), DEC);<br />
Serial.print(' ');<br />
Serial.print(now.hour(), DEC);<br />
Serial.print(':');<br />
Serial.print(now.minute(), DEC);<br />
Serial.print(':');<br />
Serial.println(now.second() + tune, DEC);<br />
<br />
Serial.println(daysOfWeek);<br />
Serial.println();<br />
<br />
<br />
<br />
<br />
}<br />
<br />
<br />
<br />
//CHECKS TO SEE IF RING TIME IS EQUAL TO CURRENT TIME<br />
boolean checkTime(int h , int m, int s)<br />
{<br />
boolean ho = false;<br />
boolean mi = false;<br />
boolean se = false;<br />
<br />
DateTime now = RTC.now();<br />
<br />
if (now.hour() == h || h == -1)<br />
{<br />
ho = true;<br />
}<br />
<br />
if (now.minute() == m || m == -1)<br />
{<br />
mi = true;<br />
}<br />
if (now.second() == (s) || s == -1) //+ tune corrects the clock's slightly off time which results from uploading.<br />
{<br />
se = true;<br />
}<br />
<br />
if (ho && mi && se)<br />
{<br />
return true;<br />
}<br />
<br />
else<br />
{<br />
return false;<br />
}<br />
}<br />
<div>
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6427771080561552950.post-85048381380516132872017-08-11T10:08:00.001-07:002017-08-11T10:08:37.349-07:00Digital Whiteboard<span id="docs-internal-guid-0b850bb8-d244-d127-b27b-b7690941e0ad"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">ProLine:</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">import processing.serial.*;</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">Serial myPort;</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">boolean firstContact = false;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int[] serialInArray = new int[2]; // Where we'll put what we receive</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int serialCount = 0; // A count of how many bytes we receive</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int x; //the x coordinate</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int y; //the y coordinate</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int mx = 250;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int my = 250;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int px = mx;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int py = my;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int ppy = mx;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int ppx = my;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int fx;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int fy;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int gx;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int gy;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int mpx;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int mpy;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int xs = 10;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int xy = 10;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int count = 2;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int counter = 0;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">void setup()</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">{</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> size(500, 500);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> background(0);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> String portName = Serial.list()[4];</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> myPort = new Serial(this, portName, 9600);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> strokeWeight(1);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> stroke(255);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> serialEvent(myPort);</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> mx = int(map(x, 0, 110, 0, 500));</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> my = int(map(y, 0, 110, 0, 500));</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<br /><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">void draw()</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">{</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (keyPressed && key == 'b' && (count%2 == 0))</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> serialEvent(myPort);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> fx = int(map(x, 0, 200, 0, 500));</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> fy = int(map(y, 0, 200, 0, 500));</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if(count == 2)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> gx = fx;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> gy = fy;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> count++;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> line(gx, gy, fx, fy);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (keyPressed && key == 'b' && (count % 2 != 0))</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> serialEvent(myPort);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> gx = int(map(x, 0, 200, 0, 500));</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> gy = int(map(y, 0, 200, 0, 500));</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> line(fx, fy, gx, gy);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> count++;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //delay(0);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //fill(0, 0, 0, 10);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //rect(0, 0, 500, 500);</span></div>
<br /><br /><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // checkValid();</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //line(mx, my, px, py);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //print("px" + px + " ");</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //print("py" + py + " ");</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //print("mx" + mx + " ");</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //print("my" + my + " ");</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //println(" ");</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if ( mx > 500 || my > 500)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> mx = px;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> my = py;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> fill(random(10, 255));</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> rect(250, 250, 50, 50);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (counter > 5)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //line(mx, my, ppx, ppy);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> counter++;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> serialEvent(myPort);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<br /><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">void serialEvent(Serial myPort) { //communication setup from arduino</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // read a byte from the serial port:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> int inByte = myPort.read();</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // if this is the first byte received, and it's an A,</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // clear the serial buffer and note that you've</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // had first contact from the microcontroller.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // Otherwise, add the incoming byte to the array:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (firstContact == false) {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (inByte == 'A') {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> myPort.clear(); // clear the serial port buffer</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> firstContact = true; // you've had first contact from the microcontroller</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> myPort.write('A'); // ask for more</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> } else {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // Add the latest byte from the serial port to array:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (serialCount < 2)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> serialInArray[serialCount] = inByte;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> serialCount++;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (serialCount > 1) { </span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (serialInArray[0] == -1 || serialInArray[1] == -1)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // myPort.clear();</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> myPort.write("A");</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> serialCount = 0;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // println("x" + x + " " + "y" + y);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> } else {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> x = serialInArray[0];</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> y = serialInArray[1];</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> println("x" + x + " " + "y" + y);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //if(x || y =</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> myPort.write('A');</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> serialCount = 0;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<br /><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">void checkValid()</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">{</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (mx <= 0)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> mx = px;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (my <= 0)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> my = py;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (mx == py)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> int tmx = mx;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> int tmy = my;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> int tpx = px;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> int tpy = py;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> mx = tmy;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> my = tmx;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> px = tpy;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> py = tpx;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<br /><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (abs(mx-px) >= 50 || abs(my-py) >= 50)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> mx = px;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> my = py;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<br /><br /><br /><br /><br /><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">Pro first:</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">import processing.serial.*;</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">Serial myPort;</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">boolean firstContact = false;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int[] serialInArray = new int[2]; // Where we'll put what we receive</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int serialCount = 0; // A count of how many bytes we receive</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int x; //the x coordinate</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int y; //the y coordinate</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int mx = 250;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int my = 250;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int px = mx;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int py = my;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int ppy = mx;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int ppx = my;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int mpx;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int mpy;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int xs = 10;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int xy = 10;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int counter = 0;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">void setup()</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">{</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> size(500, 500);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> background(0);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> String portName = Serial.list()[4];</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> myPort = new Serial(this, portName, 9600);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> strokeWeight(1);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> stroke(255);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> serialEvent(myPort);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> mx = int(map(x, 0, 110, 0, 500));</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> my = int(map(y, 0, 110, 0, 500));</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<br /><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">void draw()</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">{</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if(keyPressed)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> background(0);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //delay(0);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //fill(0, 0, 0, 10);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //rect(0, 0, 500, 500);</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> mx = int(map(x, 0, 200, 0, 500));</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> my = int(map(y, 0, 200, 0, 500));</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">// checkValid();</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //line(mx, my, px, py);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //print("px" + px + " ");</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //print("py" + py + " ");</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //print("mx" + mx + " ");</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //print("my" + my + " ");</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //println(" ");</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> ppx = px;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> ppy = py;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> px = mx;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> py = my;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if( mx > 500 || my > 500)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> mx = px;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> my = py;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> fill(random(10, 255));</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> rect(250, 250, 50, 50);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if(counter > 5)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> line(mx, my, ppx, ppy);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> counter++;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> serialEvent(myPort);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<br /><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">void serialEvent(Serial myPort) { //communication setup from arduino</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // read a byte from the serial port:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> int inByte = myPort.read();</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // if this is the first byte received, and it's an A,</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // clear the serial buffer and note that you've</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // had first contact from the microcontroller.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // Otherwise, add the incoming byte to the array:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (firstContact == false) {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (inByte == 'A') {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> myPort.clear(); // clear the serial port buffer</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> firstContact = true; // you've had first contact from the microcontroller</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> myPort.write('A'); // ask for more</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> else {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // Add the latest byte from the serial port to array:</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if(serialCount < 2)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> serialInArray[serialCount] = inByte;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> serialCount++;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (serialCount > 1) { </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if(serialInArray[0] == -1 || serialInArray[1] == -1)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // myPort.clear();</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> myPort.write("A");</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> serialCount = 0;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // println("x" + x + " " + "y" + y);</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> else{</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> x = serialInArray[0];</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> y = serialInArray[1];</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> println("x" + x + " " + "y" + y);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //if(x || y =</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> myPort.write('A');</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> serialCount = 0;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<br /><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">void checkValid()</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">{</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (mx <= 0)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> mx = px;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (my <= 0)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> my = py;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if(mx == py)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> int tmx = mx;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> int tmy = my;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> int tpx = px;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> int tpy = py;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> mx = tmy;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> my = tmx;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> px = tpy;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> py = tpx;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if(abs(mx-px) >= 50 || abs(my-py) >= 50)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> mx = px;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> my = py;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<br /><br /><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"><br class="kix-line-break" /></span><span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">Arduino:</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int trig1 = 9;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int echo1 = 10;</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int trig2 = 5;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int echo2 = 6;</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">long duration1;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">long distance1;</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">long duration2;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">long distance2;</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int board = 118;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int x;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int y;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">double a;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">double b;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">double c;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int px = x;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int py = y;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int inByte = 0;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">double theta;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">void setup() {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> pinMode(echo1, INPUT);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> pinMode(trig1, OUTPUT);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> pinMode(echo2, INPUT);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> pinMode(trig2, OUTPUT);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> Serial.begin(9600);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> establishContact();</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> // put your setup code here, to run once:</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">void loop() {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">if(Serial.available()>0)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">{</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">inByte = Serial.read();</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> a = getDistance1()+(c/2);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> delay(10);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> b = getDistance2()+(c/2);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> c = board;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">// Serial.print("a");</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">// Serial.println(a);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">// Serial.print("b");</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">// Serial.println(b);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">// Serial.println(" ");</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> theta = acos( ( (pow(a, 2))+(pow(c,2))-(pow(b,2)))/(2*a*c));</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //Serial.println(theta);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> y = a * sin(theta);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> x = a * cos(theta);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (x == 0)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> x = px;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> if (y == 0)</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> y = py;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> //</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">// Serial.write(x);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">// Serial.write(y);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> delay(20);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">// </span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">//// //</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">// Serial.print("x ");</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">// Serial.print(x);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">// Serial.print( " y ");</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">// Serial.print(y);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">// Serial.println(" ");</span></div>
<br /><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> Serial.write(px);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> Serial.write(py);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> px = x;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> py = y;</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> delay(100);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<br /><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<br /><br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int getDistance1()</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">{</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> digitalWrite(trig1, LOW); //triggers on/off and then reads data</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> delayMicroseconds(2);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> digitalWrite(trig1, HIGH);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> delayMicroseconds(10);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> digitalWrite(trig1, LOW);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> duration1 = pulseIn(echo1, HIGH);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> distance1 = (duration1 / 2) * .0344; //344 m/s = speed of sound. We're converting into cm</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> return distance1;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">int getDistance2()</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">{</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> digitalWrite(trig2, LOW); //triggers on/off and then reads data</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> delayMicroseconds(2);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> digitalWrite(trig2, HIGH);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> delayMicroseconds(10);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> digitalWrite(trig2, LOW);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> duration2 = pulseIn(echo2, HIGH);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> distance2 = (duration2 / 2) * .0344; //344 m/s = speed of sound. We're converting into cm</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> return distance2;</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
<br /><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">void establishContact() { //prints A until contact is established.</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> while (Serial.available() <= 0) {</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> Serial.print('A'); // send a capital A</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> delay(300);</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;"> }</span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">}</span></div>
</span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6427771080561552950.post-17311830428548716282017-07-06T06:58:00.002-07:002017-07-06T07:04:49.123-07:00Arduino Real Time Clock Bell System Code#include <Wire.h><br />
#include "RTClib.h"<br />
#include <Servo.h><br />
RTC_DS1307 RTC;<br />
<br />
int wait1 = 200;<br />
int wait2 = 500;<br />
<br />
int tune = 7;<br />
Servo remus;<br />
Servo spin;<br />
void setup () {<br />
pinMode(A2, OUTPUT);<br />
digitalWrite(A2, LOW);<br />
pinMode(A3, OUTPUT);<br />
digitalWrite(A3, HIGH);<br />
Serial.begin(9600);<br />
Wire.begin();<br />
RTC.begin();<br />
<br />
remus.attach(9);<br />
remus.write(100);<br />
delay(500);<br />
remus.detach();<br />
<br />
<br />
<br />
//Uncomment the line below to reset time. After uploading, re-comment the line and upload again.<br />
//Otherwise the time will reset every time you start the sketch.<br />
// RTC.adjust(DateTime(__DATE__, __TIME__));<br />
<br />
if (! RTC.isrunning()) {<br />
Serial.println("RTC is NOT running!");<br />
// following line sets the RTC to the date & time this sketch was compiled<br />
<br />
<br />
//Allows for precise time setting<br />
// RTC.setHours(15);<br />
// RTC.setMinutes(7);<br />
// RTC.setSeconds(5)<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
void loop () {<br />
<br />
printTime1(); //Calls printTime1 method to prints timestamp<br />
<br />
<br />
/*<br />
* SET BELL TIMES HERE<br />
*/<br />
//CHECK TIME SECTION<br />
//Use -1 as an input if you want any hour<br />
//FORMAT: checkTime(hour, minute, second). ring(How many times you want it to ring)<br />
//No need for "== true" because checkTime is a boolean method<br />
<br />
<br />
if (checkTime(13, 0, 20))<br />
{<br />
ring(1);<br />
}<br />
<br />
if (checkTime(9, 31, 50)) //<br />
{<br />
ring(1);<br />
<br />
}<br />
<br />
delay(1000);<br />
}<br />
<br />
<br />
<br />
<br />
<br />
//CONTROLS SERVO TO RING BELL<br />
void ring(int n)<br />
{<br />
for (int i = 0; i < n; i++)<br />
{<br />
remus.attach(9);<br />
remus.write(122);<br />
delay(300);<br />
remus.write(100);<br />
delay(500);<br />
remus.detach();<br />
}<br />
}<br />
<br />
<br />
//PRINTS TIME<br />
void printTime1()<br />
{<br />
DateTime now = RTC.now();<br />
Serial.print(now.year(), DEC);<br />
Serial.print('/');<br />
Serial.print(now.month(), DEC);<br />
Serial.print('/');<br />
Serial.print(now.day(), DEC);<br />
Serial.print(' ');<br />
Serial.print(now.hour(), DEC);<br />
Serial.print(':');<br />
Serial.print(now.minute(), DEC);<br />
Serial.print(':');<br />
Serial.print(now.second() + tune, DEC);<br />
Serial.println();<br />
}<br />
<br />
<br />
<br />
//CHECKS TO SEE IF RING TIME IS EQUAL TO CURRENT TIME<br />
boolean checkTime(int h , int m, int s)<br />
{<br />
boolean ho = false;<br />
boolean mi = false;<br />
boolean se = false;<br />
<br />
DateTime now = RTC.now();<br />
<br />
if (now.hour() == h || h == -1)<br />
{<br />
ho = true;<br />
}<br />
<br />
if (now.minute() == m || m == -1)<br />
{<br />
mi = true;<br />
}<br />
if (now.second() == (s+tune) || s == -1) //+ tune corrects the clock's slightly off time which results from uploading.<br />
{<br />
se = true;<br />
}<br />
<br />
if (ho && mi && se)<br />
{<br />
return true;<br />
}<br />
<br />
else<br />
{<br />
return false;<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6427771080561552950.post-57889657461294065522016-11-21T08:57:00.002-08:002016-11-21T08:57:58.783-08:00Arduino Reflex Test Code<br />
#include <Servo.h><br />
<br />
Servo myservo; // create servo object to control a servo<br />
// twelve servo objects can be created on most boards<br />
<br />
int pos = 0; // variable to store the servo position<br />
int but = 7;<br />
int buttonState = 0;<br />
long ran = 0;<br />
int beginTime = 0;<br />
int delTime = 0;<br />
int currTime = 0;<br />
void setup() {<br />
pinMode(but, INPUT);<br />
myservo.attach(9); // attaches the servo on pin 9 to the servo object<br />
Serial.begin(9600);<br />
}<br />
<br />
void loop() {<br />
beginTime = millis();<br />
buttonState = digitalRead(but);<br />
<br />
myservo.write(88);<br />
if(buttonState == HIGH)<br />
{<br />
tone(3, 2000, 300);<br />
<br />
delay(1000);<br />
<br />
ran = random(2000, 5000);<br />
<br />
delay(ran);<br />
<br />
<br />
<br />
myservo.write(150);<br />
<br />
delay(1000);<br />
tone(3, 3000, 300);<br />
<br />
}<br />
<br />
else<br />
{<br />
myservo.write(88);<br />
}<br />
<br />
}Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6427771080561552950.post-32765935598401456942016-06-19T16:35:00.000-07:002016-06-20T07:54:49.857-07:00Arduino Instrument Code and Fritzing<b><u>Code:</u></b><br />
int trig = 10;<br />
int echo = 11;<br />
long duration;<br />
long distance;<br />
int force;<br />
<br />
void setup() {<br />
pinMode(echo, INPUT);<br />
<br />
pinMode(trig, OUTPUT);<br />
<br />
Serial.begin(9600);<br />
}<br />
<br />
void loop() {<br />
digitalWrite(trig, LOW); //triggers on/off and then reads data<br />
delayMicroseconds(2);<br />
digitalWrite(trig, HIGH);<br />
delayMicroseconds(10);<br />
digitalWrite(trig, LOW);<br />
duration = pulseIn(echo, HIGH);<br />
distance = (duration / 2) * .0344; //344 m/s = speed of sound. We're converting into cm<br />
<br />
<br />
<br />
int notes[7] = {261, 294, 329, 349, 392, 440, 494}; //Putting several notes in an array<br />
// mid C D E F G A B<br />
<br />
force = analogRead(A0); //defining force as FSR data<br />
<br />
<br />
if (distance < 0 || distance > 50 || force < 100) { //if not presed and not in front<br />
<br />
noTone(12); //dont play music<br />
<br />
}<br />
<br />
else if ((force > 100)) { //if pressed<br />
<br />
int sound = map(distance, 0, 50, 0, 6); //map distance to the array of notes<br />
tone(12, notes[sound]); //call a certain note depending on distance<br />
<br />
}<br />
<br />
<br />
}<br />
<div>
<br /></div>
<div>
<b><u>Fritzing:</u></b></div>
<div>
<b><u><br /></u></b></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgopOwH54gc2c7rf2LNEVw2XAdmmz_aqPQB5m0FLrZjxkvdUfGK_v8RlyTnEOM9q2V3V2-DeGkTVlbyR788wK6fin7Vahm3HTPoJo6iT1Pw4QAj708x8zjMOAX8glBgG10IZrKLUAOwjrk/s1600/Screen+Shot+2016-06-20+at+10.36.04+AM.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="256" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgopOwH54gc2c7rf2LNEVw2XAdmmz_aqPQB5m0FLrZjxkvdUfGK_v8RlyTnEOM9q2V3V2-DeGkTVlbyR788wK6fin7Vahm3HTPoJo6iT1Pw4QAj708x8zjMOAX8glBgG10IZrKLUAOwjrk/s400/Screen+Shot+2016-06-20+at+10.36.04+AM.png" width="400" /></a></div>
<b><u><br /></u></b></div>
<div>
<b><u><br /></u></b></div>
Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-6427771080561552950.post-78297735733715391782016-06-15T15:07:00.001-07:002016-06-15T15:07:02.831-07:00Laser pointer servo/* Sweep<br />
by BARRAGAN <http://barraganstudio.com><br />
This example code is in the public domain.<br />
<br />
modified 8 Nov 2013<br />
by Scott Fitzgerald<br />
http://www.arduino.cc/en/Tutorial/Sweep<br />
*/<br />
<br />
#include <Servo.h><br />
//int pos;<br />
int posit;<br />
Servo servo1; // create servo object to control a servo<br />
Servo servo2; // create servo object to control a servo<br />
// twelve servo objects can be created on most boards<br />
<br />
<br />
void setup() {<br />
servo1.attach(9); // attaches the servo on pin 9 to the servo object<br />
servo2.attach(10);<br />
Serial.begin(9600);<br />
servo1.write(5);<br />
servo2.write(5);<br />
delay(20);<br />
}<br />
<br />
void loop() {<br />
posit = servo1.read();<br />
<br />
long horRand1 = random(30, 150);<br />
Serial.println(horRand1);<br />
Serial.println("1");<br />
if (posit >= horRand1 ) {<br />
Serial.println("2");<br />
for (long pos = posit; pos >= horRand1; pos -= 1) {<br />
servo1.write(pos);<br />
//Serial.println("3");<br />
delay(20);<br />
Serial.println(pos);<br />
}<br />
Serial.println("4");<br />
}<br />
else {<br />
for (long pos = posit; pos <= horRand1; pos += 1){<br />
servo1.write(pos);<br />
delay(20);<br />
}<br />
}<br />
<br />
<br />
posit = servo2.read();<br />
long vertRand2 = random(0, 100);<br />
Serial.println(vertRand2);<br />
if (posit >= vertRand2) {<br />
for (long pos = posit; pos >= vertRand2; pos -= 1) {<br />
servo2.write(pos);<br />
delay(20);<br />
}<br />
}<br />
else {<br />
for (long pos = posit; pos <= vertRand2; pos += 1){<br />
servo2.write(pos);<br />
delay(20);<br />
}<br />
}<br />
<br />
}<br />
<div>
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6427771080561552950.post-6262900888991178192016-06-13T12:13:00.001-07:002016-06-13T12:33:36.918-07:00Piezo Buzzer: Code and Fritzing<b><u>On this Page:</u></b><br />
<br />
<ul>
<li><b><i>Helpful Links</i></b></li>
<li><b><i>Example Code in Video</i></b></li>
<li><b><i>Fritzing Electrical Diagram</i></b></li>
<li><b><i>Harder but more Efficient code with For Loop</i></b></li>
</ul>
<br />
<b><br /></b><b>Copy and paste code into Arduino IDE</b><br />
<b><br /></b><b>Note: </b>if you want to play different pitches on multiple pins, you need to call noTone() on the pin playing before using tone() on the next pin<br />
<br />
<br />
<br />
<br />
<br />
<b>Helpful Links: </b><br />
-<a href="https://www.arduino.cc/en/Tutorial/PlayMelody">Arduino Code a Melody</a> <br />-<a href="https://learn.sparkfun.com/tutorials/sik-experiment-guide-for-arduino---v32/experiment-11-using-a-piezo-buzzer">Sparkfun Piezo Experiment Guide</a><br />
-<a href="https://www.arduino.cc/en/Reference/Tone">Arduino Tone() Info</a><br />
<b><br /></b>
<b>Example Code in Video:</b><br />
<br />
void setup() {<br />
pinMode(12, OUTPUT);<br />
}<br />
<br />
void loop() {<br />
tone(12, 261); //Middle C<br />
delay(1000);<br />
<br />
tone(12, 277); //C#<br />
delay(1000);<br />
<br />
tone(12, 294); //D<br />
delay(1000);<br />
<br />
tone(12, 311); //D#<br />
delay(1000);<br />
<br />
tone(12, 330); //E<br />
delay(1000);<br />
<br />
tone(12, 349); //F<br />
delay(1000);<br />
<br />
tone(12, 370); //F#<br />
delay(1000);<br />
<br />
tone(12, 392); //G<br />
delay(1000);<br />
<br />
tone(12, 415); //G#<br />
delay(1000);<br />
<br />
tone(12, 440); //A<br />
delay(1000);<br />
// put your main code here, to run repeatedly:<br />
<br />
}<br />
<br />
<br />
<b>Fritzing Electrical Diagram:</b><br />
<b><br /></b>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9FNxnWeZx13eVxcqllxh1wh9q88Y4iz9shpe0akBpSMgmMle4UufgYqsiGXFIn97zaCo2FV7VuO5EmvzvIPrsEEOFs6WzGnYb159HvyfUhNV3sbUfEb3Z3I2OckmaPAGcqf_b_PxE8KI/s1600/Fritzing+Piezo.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="260" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9FNxnWeZx13eVxcqllxh1wh9q88Y4iz9shpe0akBpSMgmMle4UufgYqsiGXFIn97zaCo2FV7VuO5EmvzvIPrsEEOFs6WzGnYb159HvyfUhNV3sbUfEb3Z3I2OckmaPAGcqf_b_PxE8KI/s320/Fritzing+Piezo.jpg" width="320" /></a></div>
<br />
<br />
<b><br /></b>
<b><br /></b>
<b><br /></b><br />
<b><br /></b>
<b><br /></b>
<b><br /></b>
<b><br /></b>
<b><br /></b>
<b><br /></b>
<b><br /></b>
<b><br /></b>
<b><br /></b>
<b><br /></b>
<b><br /></b>
<b><br /></b>
<b>Harder but Efficient Code with For Loop:</b><br />
<b><br /></b>
<br />
<br />
void setup() {<br />
pinMode(12, OUTPUT);<br />
}<br />
<br />
void loop() {<br />
int notes[10]={261, 277, 294, 311, 330, 349, 370, 392, 415, 440};<br />
// mid C C# D D# E F F# G G# A<br />
<br />
for(int i = 0; i < 10; i++){<br />
tone(12, notes[i]); //accesses spots on the array.<br />
delay(1000);<br />
}<br />
<br />
<br />
}<br />
<br />
<br />
<br />Unknownnoreply@blogger.com5tag:blogger.com,1999:blog-6427771080561552950.post-74812798100043948632016-06-04T08:33:00.000-07:002017-03-09T06:45:17.286-08:00Force Sensor: Code and Wiring<b><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIGlsfy9ZzjwrF4TQvFuCN2oieiQcZQRb-2Z2YQrIXZTNp79IH2C1GZuB2Q6OAHFOFklMz7v1zs1HqF-XgfXmK56A8PVkpzR6vs8hg9mhHirhJghbH3su9Mw_pqjn6LLl0pmSfNUwnxbw/s1600/Screen+Shot+2017-03-09+at+9.38.51+AM.png" imageanchor="1"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIGlsfy9ZzjwrF4TQvFuCN2oieiQcZQRb-2Z2YQrIXZTNp79IH2C1GZuB2Q6OAHFOFklMz7v1zs1HqF-XgfXmK56A8PVkpzR6vs8hg9mhHirhJghbH3su9Mw_pqjn6LLl0pmSfNUwnxbw/s320/Screen+Shot+2017-03-09+at+9.38.51+AM.png" width="240" /></a></b><br />
<b><br /></b>
<b>Code:</b><br />
<br />
<br />
<div style="text-align: left;">
int pressurePin = A0;</div>
<div style="text-align: left;">
int force;</div>
<div style="text-align: left;">
int LEDpin = 12;</div>
<div style="text-align: left;">
void setup() {</div>
<div style="text-align: left;">
Serial.begin(9600);</div>
<div style="text-align: left;">
pinMode(LEDpin, OUTPUT);</div>
<div style="text-align: left;">
}</div>
<div style="text-align: left;">
void loop() {</div>
<div style="text-align: left;">
force = analogRead(pressurePin);</div>
<div style="text-align: left;">
Serial.println(force);</div>
<div style="text-align: left;">
if(force > 500)</div>
<div style="text-align: left;">
{</div>
<div style="text-align: left;">
digitalWrite(LEDpin, HIGH);</div>
<div style="text-align: left;">
}</div>
<div style="text-align: left;">
else</div>
<div style="text-align: left;">
{</div>
<div style="text-align: left;">
digitalWrite(LEDpin, LOW);</div>
<div style="text-align: left;">
}</div>
<div style="text-align: left;">
delay(100);</div>
<div style="text-align: left;">
}</div>
<br />
<br />
<br />
<b><br /></b>
<b><br /></b>
<b>Wiring Diagram:</b><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKfJ8cWERihDlD_PUsJ9Xd_AqYZj11DWDgqZOla1kX6ORca2L-hpetthTol2vRvv6i0ETWFZvJJuRHLfTFMquQBX4KwrGdBu_hFah0JM4CN662XTprN-JRsNnoBGPlfrhibtQnlfzPlkE/s1600/FSR+FRZ.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKfJ8cWERihDlD_PUsJ9Xd_AqYZj11DWDgqZOla1kX6ORca2L-hpetthTol2vRvv6i0ETWFZvJJuRHLfTFMquQBX4KwrGdBu_hFah0JM4CN662XTprN-JRsNnoBGPlfrhibtQnlfzPlkE/s400/FSR+FRZ.jpg" width="307" /></a></div>
<br />Unknownnoreply@blogger.com16tag:blogger.com,1999:blog-6427771080561552950.post-75225671910811866312016-05-06T15:06:00.001-07:002016-05-06T15:06:11.903-07:00Ultrasonic Tutorial Codeint trig = 10;<br />int echo = 9;<br />int duration;<br />int distance;<br /><br />void setup() {<br /> pinMode(echo, INPUT);<br /> pinMode(trig, OUTPUT);<br /> Serial.begin(9600);<br />}<br /><br />void loop() {<br /> digitalWrite(trig, LOW);<br /> delay(.002);<br /> digitalWrite(trig, HIGH);<br /> delay(.01);<br /> digitalWrite(trig, LOW);<br /> duration = pulseIn(echo, HIGH); //record the time it takes for the sound to return<br /> distance = (duration / 2) / 29.1; //convert the time to distance<br /><br /> Serial.println(distance);<br /> delay(100);<br /><br />}Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6427771080561552950.post-73152739228367910122016-04-10T09:34:00.003-07:002016-04-10T09:34:53.274-07:00Carduino Plug and Play Code (copy and paste)// Adafruit Motor shield library<br />// copyright Adafruit Industries LLC, 2009<br />// this code is public domain, enjoy!<br />//Modified by Sam<br /><br />#include <AFMotor.h> //Includes the Adafruit Motor Shield Library<br /><br /><br />AF_DCMotor motor1(1); // DC motor is hooked up to M1 <br />AF_DCMotor motor2(2); // DC motor is hooked up to M2<br />//==================INSERT VALUES HERE \/ ====================================================================================================<br />int pin1 = 22; // CHANGE 22 TO THE NUMBER OF PIN YOU ARE USING!!!! Digital pins connected to the radio receiver ports =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~<br />int pin2 = 30; //CHANGE 30 TO THE NUMBER OF PIN YOU ARE USING!!!! ^ The receiver is the small black box w/ a red antenna=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~<br />//Make sure that pin1 is hooked up to the throttle port on the receiver (port 2 on 9x)<br />//and that pin2 is hooked up to the rudder port on the receiver (port 4 on 9x)<br /><br /><br />int neutralh = 1500;//PUT YOUR HIGH NEUTRAL VALUE HERE. REPLACE 1500 =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~<br />int neutrall = 1420;//PUT YOUR LOW NEUTRAL VALUE HERE. REPLACE 1420 =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~<br />int maxval = 1870; //PUT YOUR MAX VALUE HERE REPLACE 1870 =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~==~=~==~=~==~=~==~=~==~=~==~=~=<br />int minval = 1050; // PUT YOUR MIN VALUE HERE REPLACE 1050 =~=~==~=~==~=~==~=~==~=~==~=~==~=~==~=~==~=~==~=~==~=~==~=~==~=~==~=~==~=~==~=~==~=~==~=~==~=~==~=~==~=~==~=~==~<br />//==================INSERT VALUES HERE /\ ====================================================================================================<br /><br />void setup() {<br /> Serial.begin(9600); // set up Serial monitor at 9600 bps<br /><br /> motor1.run(RELEASE); //This releases the motors via the motorshield<br /> motor2.run(RELEASE); //^ This is to make sure the motors dont start w/o control<br /><br /> pinMode(pin1, INPUT); //Setting up RC input pins<br /> pinMode(pin2, INPUT); //Setting up RC input pins<br /><br /><br />void loop() {<br /> int sV1; //These are all different speed values that will be mapped<br /> int sV2;<br /> int sV3;<br /> int sV4;<br /> int sV5;<br /> int sV6;<br /><br /> int speedValue = pulseIn(pin1, HIGH); //Getting the pulse in value from pin 1 and defining pin1 as speed<br /> <br /> int directionValue = pulseIn(pin2, HIGH); //Getting the pulse in value from pin 2 and defining pin1 as turning<br /><br /> //Serial.println(speedValue);<br /> //Serial.println(directionValue);<br /> //These can be printed for debugging<br /><br /><br /> <br /><br /> if (speedValue >= 1420 && speedValue <= 1500) { //If the sticks are Neutral, then stay still<br /><br /> motor1.run(RELEASE); //releases motors<br /> motor2.run(RELEASE); // releases motors<br /><br /> delay(50); //checks again every 50 micro Seconds<br /> }<br /><br /><br /> if (speedValue > 1500 && directionValue >= 1420 && directionValue <= 1500) { //if the throttle is up and turning is neutral<br /><br /> sV1 = map(speedValue, 1500, 1870, 140, 255); //Maps the pulseIn speedvalue to numbers the motors can read<br /> //Motor is set to 140-255 instead of 0-255 so that the motor doesnt stall if <br /> //it is powered at too low of a level<br /> <br /> if(sV1 > 255){ //If the speed value is over 255 then set it to 255. .<br /> sV1 = 255; //This prevents overpowering the motor if there is a pulsein glitch <br /> }<br /> <br /> motor1.setSpeed(sV1); // Sets the speed of motor1 to the speedValue<br /> motor2.setSpeed(sV1); // Sets the speed of motor2 to the speedValue<br /> motor1.run(FORWARD); //Makes the motor go forward at the speed defined above<br /> motor2.run(FORWARD); //Makes the motor go forward at the speed defined above<br /> delay(50); //Repeat every 50 micro seconds<br /> <br /> }<br /><br /><br /> if (directionValue > neutralh && speedValue > neutralh) { //Speed value is forward, direction is right<br /><br /> sV2 = map(speedValue, neutralh, maxval, 140, 255); //RIGHT FORWARD<br /><br /> if(sV2 > 255){<br /> sV2 = 255;<br /> }<br /><br /> motor1.setSpeed(0);<br /> motor2.setSpeed(sV2);<br /> motor1.run(FORWARD);<br /> motor2.run(FORWARD);<br /> Serial.println("B");<br /> delay(50);<br /> }<br /><br /> if (directionValue < neutrall && speedValue > neutralh) { //Speed is forward, Direction is left<br /><br /> sV3 = map(speedValue, neutralh, maxval, 140, 255); //LEFT FORWARD<br /><br /> if(sV3 > 255){<br /> sV3 = 255;<br /> }<br /><br /> motor1.setSpeed(sV3);<br /> motor2.setSpeed(0);<br /> motor1.run(FORWARD);<br /> motor2.run(FORWARD);<br /> Serial.println("C");<br /><br /> delay(50);<br /> }<br /><br /> if (speedValue < neutrall && directionValue >= neutrall && directionValue <= neutralh) { //Speed is reverse and direction value is centered<br /><br /> sV4 = map(speedValue, neutrall, minval, 140, 255); //REVERSE<br /><br /> if(sV4 > 255){<br /> sV4 = 255;<br /> }<br /><br /> motor1.setSpeed(sV4);<br /> motor2.setSpeed(sV4);<br /> motor1.run(BACKWARD);<br /> motor2.run(BACKWARD);<br /> Serial.println("D");<br /><br /> delay(50);<br /> }<br /><br /> if (directionValue > neutralh && speedValue < neutrall) {<br /><br /> sV5 = map(speedValue, neutralh, minval, 140, 255); //BACK RIGHT<br /><br /> if(sV5 > 255){<br /> sV5 = 255;<br /> }<br /><br /> motor1.setSpeed(sV5);<br /> motor2.setSpeed(0);<br /> motor1.run(BACKWARD);<br /> motor2.run(BACKWARD);<br /> Serial.println("E");<br /><br /> delay(50);<br /> }<br /><br /> if (directionValue < neutrall && speedValue < neutrall) {<br /><br /> sV6 = map(speedValue, neutralh, minval, 140, 255); //BACK LEFT<br /><br /> if(sV6 > 255){<br /> sV6 = 255;<br /> }<br /><br /> motor1.setSpeed(0);<br /> motor2.setSpeed(sV6);<br /> motor1.run(BACKWARD);<br /> motor2.run(BACKWARD);<br /> Serial.println("F");<br /><br /> delay(50);<br /> <br /> }<br />}Unknownnoreply@blogger.com4tag:blogger.com,1999:blog-6427771080561552950.post-66649404635893371542016-04-10T09:32:00.000-07:002016-04-10T09:55:55.295-07:00Carduino Remote Test Code (copy and paste this into a new arduino IDE sketch)int pin1 = 22; //REPLACE 22 WITH YOUR PIN<br />
int pin2 = 30; //REPLACE 30 WITH YOUR PIN<br />
<br />
<br />
<br />
void setup() {<br />
Serial.begin(9600);<br />
pinMode(pin1, INPUT);<br />
pinMode(pin2, INPUT);<br />
<br />
}<br />
<br />
void loop() {<br />
int speedValue = pulseIn(pin1, HIGH);<br />
int directionValue = pulseIn(pin2, HIGH);<br />
<br />
//Serial.println(speedValue);<br />
Serial.println(directionValue);<br />
<br />
delay(50);<br />
<br />
}Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6427771080561552950.post-72290628915584474762016-01-16T07:42:00.000-08:002016-01-16T10:17:34.835-08:00Project #2: Arduino Timelapse Auto-Rotator <br />
#include <Servo.h><br />
<br />
Servo myservo; // create servo object to control a servo<br />
// twelve servo objects can be created on most boards<br />
<br />
int pos = 0; // variable to store the servo position<br />
int potPin = 1;<br />
int val = 0;<br />
<br />
void setup() {<br />
myservo.attach(8); // attaches the servo on pin 9 to the servo object<br />
Serial.begin(9600);<br />
}<br />
<br />
void loop() {<br />
val = analogRead(potPin);<br />
<br />
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees<br />
// in steps of 1 degree<br />
val = analogRead(potPin);<br />
myservo.write(pos); <br />
Serial.println(val*10);// tell servo to go to position in variable 'pos'<br />
delay(val*10); // waits 15ms for the servo to reach the position<br />
<br />
}<br />
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees<br />
val = analogRead(potPin);<br />
myservo.write(pos); <br />
Serial.println(val*10); // tell servo to go to position in variable 'pos'<br />
delay(val*10); // pot controls delay<br />
<br />
}<br />
}Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6427771080561552950.post-51045581558225456312016-01-04T06:47:00.002-08:002016-01-04T06:47:39.308-08:00Processing Code Ultrasonic Project<div>
import processing.serial.*; //processing serial library</div>
<div>
<br /></div>
<div>
Serial myPort; // The serial port</div>
<div>
int[] serialInArray = new int[9]; // Where we'll put what we receive</div>
<div>
int serialCount = 0; // A count of how many bytes we receive</div>
<div>
int x; //the x coordinate</div>
<div>
int y; //the y coordinate</div>
<div>
int px = x; //px and py equal to x and y</div>
<div>
int py = y;</div>
<div>
int prx; //previous x/y for other loops</div>
<div>
int pry;</div>
<div>
int lx; //more x/y alternates</div>
<div>
int ly;</div>
<div>
int lpx; //more px/py alternates</div>
<div>
int lpy; </div>
<div>
int button1val; //buton values</div>
<div>
int button2val;</div>
<div>
int button3val;</div>
<div>
int button0val;</div>
<div>
int r1 = 0; //radius values</div>
<div>
int r2 = 0;</div>
<div>
int w1= 0; //width values</div>
<div>
int w2 = 0;</div>
<div>
int counter = 0; //counters in loops</div>
<div>
int counter1 = 0;</div>
<div>
int colorval; //color values</div>
<div>
int colorval1;</div>
<div>
int colorval2;</div>
<div>
int colorval3;</div>
<div>
float colorvala; //color float for weird situations</div>
<div>
<br /></div>
<div>
boolean firstContact = false; // Whether we've heard from the microcontroller</div>
<div>
<br /></div>
<div>
void setup() {</div>
<div>
size(600, 400); // Stage size</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
//println(Serial.list()[0]);</div>
<div>
<br /></div>
<div>
//String portName = Serial.list()[3];</div>
<div>
myPort = new Serial(this, "COM5", 9600); //setting up communication</div>
<div>
<br /></div>
<div>
x=300;</div>
<div>
y=300;</div>
<div>
background(0, 0, 0);</div>
<div>
}</div>
<div>
<br /></div>
<div>
void draw() {</div>
<div>
</div>
<div>
</div>
<div>
//COLOR SECTION-----------------------<wbr></wbr>------------------------------<wbr></wbr>--------------</div>
<div>
colorvala = map(colorval, 0, 255, 0, 1024);</div>
<div>
if(colorvala >0 && colorvala<171) //WHITE</div>
<div>
{</div>
<div>
colorval1 = 255;</div>
<div>
colorval2 = 255;</div>
<div>
colorval3 = 255;</div>
<div>
}</div>
<div>
else if(colorvala >171 && colorvala < 342) //GREY</div>
<div>
{</div>
<div>
colorval1 = 96;</div>
<div>
colorval2 = 96;</div>
<div>
colorval3 = 96;</div>
<div>
}</div>
<div>
else if(colorvala >342 && colorvala < 513) //BLUE</div>
<div>
{</div>
<div>
colorval1 = 0;</div>
<div>
colorval2 = 0;</div>
<div>
colorval3 = 255;</div>
<div>
}</div>
<div>
</div>
<div>
else if(colorvala >513 && colorvala < 684) //BLUE</div>
<div>
{</div>
<div>
colorval1 = 0;</div>
<div>
colorval2 = 153;</div>
<div>
colorval3 = 0;</div>
<div>
}</div>
<div>
else if(colorvala >684 && colorvala < 855) //BLUE</div>
<div>
{</div>
<div>
colorval1 = 255;</div>
<div>
colorval2 = 255;</div>
<div>
colorval3 = 0;</div>
<div>
}</div>
<div>
else if(colorvala >855 && colorvala < 1024) //BLUE</div>
<div>
{</div>
<div>
colorval1 = 255;</div>
<div>
colorval2 = 0;</div>
<div>
colorval3 = 0;</div>
<div>
}</div>
<div>
</div>
<div>
</div>
<div>
fill(colorval1, colorval2, colorval3); </div>
<div>
stroke(255);</div>
<div>
strokeWeight(3);</div>
<div>
ellipse(575,375, 15, 15);</div>
<div>
println(colorval);</div>
<div>
</div>
<div>
//END COLOR SECTION-----------------------<wbr></wbr>------------------------------<wbr></wbr>--------------</div>
<div>
</div>
<div>
</div>
<div>
if (x >= 2 && x <= 35 && y >= 2 && y <= 35)</div>
<div>
{</div>
<div>
lx=x;</div>
<div>
ly=y;</div>
<div>
lpx=px;</div>
<div>
lpy=py;</div>
<div>
<br /></div>
<div>
if (button2val==0)</div>
<div>
{</div>
<div>
</div>
<div>
<br /></div>
<div>
if (counter <1)</div>
<div>
{</div>
<div>
prx = x;</div>
<div>
pry = y;</div>
<div>
println(counter);</div>
<div>
counter = counter + 1;</div>
<div>
}</div>
<div>
if (counter>=1)</div>
<div>
{</div>
<div>
println(counter);</div>
<div>
stroke(0);</div>
<div>
ellipse(prx*20, pry*20, r1, r2);</div>
<div>
r1=r1+5;</div>
<div>
r2=r2+5;</div>
<div>
fill(255);</div>
<div>
}</div>
<div>
</div>
<div>
</div>
<div>
} </div>
<div>
else</div>
<div>
{ </div>
<div>
r1=0;</div>
<div>
r2=0;</div>
<div>
counter=0;</div>
<div>
</div>
<div>
}</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
if (button0val == 0) //if the button is pressed</div>
<div>
{</div>
<div>
if (counter1 < 1) //if the counter is less than zero</div>
<div>
{</div>
<div>
prx = x; //this other previous x/y is x/y</div>
<div>
pry = y; </div>
<div>
counter1 = counter1 + 1; //this pretty much locks the shape into place,</div>
<div>
//so it doesn't move</div>
<div>
}</div>
<div>
if (counter1 >= 1) //if the counter is greater than one</div>
<div>
{</div>
<div>
rectMode(CENTER); //make a rectangle</div>
<div>
stroke(0);</div>
<div>
rect((prx*20), (pry*20), w1, w2); </div>
<div>
w1=w1+5; //that keeps expanding</div>
<div>
w2=w2+5;</div>
<div>
fill(255);</div>
<div>
</div>
<div>
}</div>
<div>
}</div>
<div>
else {</div>
<div>
w1=0; //otherwise no circle 4 u</div>
<div>
w2=0;</div>
<div>
counter1 = 0; //unlock</div>
<div>
}</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
if (button1val == 0)</div>
<div>
{</div>
<div>
//alternate line code if I ever want to use it</div>
<div>
//this is where px and py come in. only really used here.</div>
<div>
//stroke(255, 255, 255);</div>
<div>
//strokeWeight(1);</div>
<div>
//line(((lx+lpx)/2)*20, ((lx+lpx)/2)*20, lpy*20, lpx*10);</div>
<div>
stroke(0);</div>
<div>
fill(colorval1, colorval2, colorval3);</div>
<div>
ellipse(((lx+lpx)/2)*20, ((ly+lpy)/2)*20, 20, 20); //turn the x and y into variables with that formula.</div>
<div>
//then do previous variables with that same formula</div>
<div>
<br /></div>
<div>
print(ly); //printing for bug checking</div>
<div>
print(" ");</div>
<div>
print(lx);</div>
<div>
print(" ");</div>
<div>
print(lpy);</div>
<div>
print(" ");</div>
<div>
println(lpx);</div>
<div>
print("b1 =");</div>
<div>
println(button1val);</div>
<div>
print("b2 =");</div>
<div>
println(button2val);</div>
<div>
}</div>
<div>
<br /></div>
<div>
if (button3val == 0) { //if I press the clear button </div>
<div>
background(0); //reset the background. This covers everthing up</div>
<div>
//looks like it is being all erased, but we just cover it up</div>
<div>
}</div>
<div>
}</div>
<div>
}</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
void serialEvent(Serial myPort) { //communication setup from arduino</div>
<div>
//see video description to the link that I used some code for this section from</div>
<div>
// read a byte from the serial port:</div>
<div>
int inByte = myPort.read();</div>
<div>
// if this is the first byte received, and it's an A,</div>
<div>
// clear the serial buffer and note that you've</div>
<div>
// had first contact from the microcontroller.</div>
<div>
// Otherwise, add the incoming byte to the array:</div>
<div>
if (firstContact == false) {</div>
<div>
if (inByte == 'A') {</div>
<div>
myPort.clear(); // clear the serial port buffer</div>
<div>
firstContact = true; // you've had first contact from the microcontroller</div>
<div>
myPort.write('A'); // ask for more</div>
<div>
}</div>
<div>
} else {</div>
<div>
// Add the latest byte from the serial port to array:</div>
<div>
serialInArray[serialCount] = inByte;</div>
<div>
serialCount++;</div>
<div>
<br /></div>
<div>
// If we have 3 bytes:</div>
<div>
if (serialCount > 8) { //if it is divisible by 3</div>
<div>
x = serialInArray[0];</div>
<div>
y = serialInArray[1];</div>
<div>
px = serialInArray[2];</div>
<div>
py = serialInArray[3];</div>
<div>
button1val = serialInArray[4];</div>
<div>
button2val = serialInArray[5];</div>
<div>
button3val = serialInArray[6];</div>
<div>
button0val = serialInArray[7];</div>
<div>
colorval = serialInArray[8];</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
// Send a capital A to request new sensor readings:</div>
<div>
myPort.write('A');</div>
<div>
// Reset serialCount:</div>
<div>
serialCount = 0;</div>
<div>
}</div>
<div>
}</div>
<div>
}</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6427771080561552950.post-84565315616687960812016-01-04T06:45:00.001-08:002016-01-04T06:45:51.966-08:00Arduino Ultrasonic Project<div dir="ltr">
<div>
int trig2 = 11; //Trig and echo pin setup for the Ultrasonic sensors</div>
<div>
int echo2 = 10;</div>
<div>
<br /></div>
<div>
int trig1 = 13;</div>
<div>
int echo1 = 12;</div>
<div>
<br /></div>
<div>
int trig3 = 7;</div>
<div>
int echo3 = 6;</div>
<div>
<br /></div>
<div>
int trig4 = 4;</div>
<div>
int echo4 = 3;</div>
<div>
<br /></div>
<div>
int button1 = 8; //Button variable setup</div>
<div>
int button2 = 9;</div>
<div>
int button3 = 2;</div>
<div>
int button0 = 5;</div>
<div>
<br /></div>
<div>
int x; //x integer for the x coordinate</div>
<div>
int y; //y integer for the y coordinate</div>
<div>
int px = x; //sets previous x as x</div>
<div>
int py = y; // sets previous y as y</div>
<div>
int inByte = 0; //For arduino to processing serial com</div>
<div>
int s1 = 4; //sesnor region 1</div>
<div>
int s12 = 6; //sesnor region 1 and 2</div>
<div>
int s2 = 8; //sesnor region 2</div>
<div>
int s23 = 10; //sesnor region 2 and 3</div>
<div>
int s3 = 12; //sesnor region 3</div>
<div>
int s34 = 14; //sesnor region 3 and 4</div>
<div>
int s4 = 16; //sesnor region 4</div>
<div>
<br /></div>
<div>
int potpin = 2; //potentiometer pin</div>
<div>
int pot; //potentiometer value</div>
<div>
int colorval; //color value (from potentiometer)</div>
<div>
<br /></div>
<div>
void setup() {</div>
<div>
Serial.begin (9600);</div>
<div>
<br /></div>
<div>
pinMode(trig2, OUTPUT);</div>
<div>
pinMode(echo2, INPUT);</div>
<div>
<br /></div>
<div>
pinMode(trig4, OUTPUT);</div>
<div>
pinMode(echo4, INPUT);</div>
<div>
<br /></div>
<div>
pinMode(trig3, OUTPUT);</div>
<div>
pinMode(echo3, INPUT);</div>
<div>
<br /></div>
<div>
pinMode(trig1, OUTPUT);</div>
<div>
pinMode(echo1, INPUT);</div>
<div>
<br /></div>
<div>
pinMode(button1, INPUT);</div>
<div>
pinMode(button2, INPUT);</div>
<div>
pinMode(button3, INPUT);</div>
<div>
pinMode(button0, INPUT);</div>
<div>
<br /></div>
<div>
establishContact(); //establish contact with processing</div>
<div>
}</div>
<div>
<br /></div>
<div>
void loop() {</div>
<div>
int button1val = digitalRead(button1); //setting up buttons</div>
<div>
int button2val = digitalRead(button2);</div>
<div>
int button3val = digitalRead(button3);</div>
<div>
int button0val = digitalRead(button0);</div>
<div>
pot= analogRead(potpin); //reads potentiometer value</div>
<div>
colorval = pot; //translates pot val to color</div>
<div>
</div>
<div>
if (Serial.available() > 0)</div>
<div>
{</div>
<div>
inByte = Serial.read();</div>
<div>
long duration2, distance2; //duration and distance for the sensors</div>
<div>
long duration4, distance4;</div>
<div>
long duration3, distance3;</div>
<div>
long duration1, distance1;</div>
<div>
<br /></div>
<div>
</div>
<div>
digitalWrite(trig2, LOW); //trigger the ultrasonic pins</div>
<div>
delay(.002);</div>
<div>
digitalWrite(trig2, HIGH);</div>
<div>
delay(.01);</div>
<div>
digitalWrite(trig2, LOW);</div>
<div>
duration2 = pulseIn(echo2, HIGH); //record the time it takes for the sound to return</div>
<div>
distance2 = (duration2 / 2) / 29.1; //convert the time to distance</div>
<div>
<br /></div>
<div>
digitalWrite(trig4, LOW);</div>
<div>
delay(.002);</div>
<div>
digitalWrite(trig4, HIGH);</div>
<div>
delay(.01);</div>
<div>
digitalWrite(trig4, LOW);</div>
<div>
duration4 = pulseIn(echo4, HIGH);</div>
<div>
distance4 = (duration4 / 2) / 29.1;</div>
<div>
<br /></div>
<div>
digitalWrite(trig3, LOW);</div>
<div>
delay(.002);</div>
<div>
digitalWrite(trig3, HIGH);</div>
<div>
delay(.01);</div>
<div>
digitalWrite(trig3, LOW);</div>
<div>
duration3 = pulseIn(echo3, HIGH);</div>
<div>
distance3 = (duration3 / 2) / 29.1;</div>
<div>
<br /></div>
<div>
digitalWrite(trig1, LOW);</div>
<div>
delay(.002);</div>
<div>
digitalWrite(trig1, HIGH);</div>
<div>
delay(.01);</div>
<div>
digitalWrite(trig1, LOW);</div>
<div>
duration1 = pulseIn(echo1, HIGH);</div>
<div>
distance1 = (duration1 / 2) / 29.1;</div>
<div>
<br /></div>
<div>
if (distance1 <30 && distance2 >30) //If sensor detects in a certain area </div>
<div>
{</div>
<div>
x = distance1; //set x and y to the recorded distances</div>
<div>
y = s1;</div>
<div>
}</div>
<div>
else if (distance1 <30 && distance2 <30) </div>
<div>
{</div>
<div>
x = ((distance1+distance2)/2);</div>
<div>
y = s12;</div>
<div>
}</div>
<div>
else if (distance2 <30 && distance3 >30) //different statements for different sensors</div>
<div>
{</div>
<div>
x = distance2;</div>
<div>
y = s2;</div>
<div>
}</div>
<div>
else if (distance2 <30 && distance3 <30)</div>
<div>
{</div>
<div>
x = ((distance2+distance3)/2);</div>
<div>
y = s23;</div>
<div>
}</div>
<div>
else if (distance2 >30 && distance3 <30)</div>
<div>
{</div>
<div>
x = distance3;</div>
<div>
y = s3;</div>
<div>
}</div>
<div>
else if (distance3 <30 && distance4 <30)</div>
<div>
{</div>
<div>
x = ((distance3+distance4)/2);</div>
<div>
y = s34;</div>
<div>
}</div>
<div>
<br /></div>
<div>
else if (distance3 >30 && distance4 <30)</div>
<div>
{</div>
<div>
x = distance4;</div>
<div>
y = s4;</div>
<div>
}</div>
<div>
</div>
<div>
</div>
<div>
Serial.write(x); //Serial write everything (sends it to processing via serial)</div>
<div>
Serial.write(y); </div>
<div>
Serial.write(px);</div>
<div>
Serial.write(py);</div>
<div>
Serial.write(button1val);</div>
<div>
Serial.write(button2val);</div>
<div>
Serial.write(button3val);</div>
<div>
Serial.write(button0val);</div>
<div>
Serial.write(colorval);</div>
<div>
px = x; //Set px and py to x and y (used if lines are reimplemented)</div>
<div>
py= y; </div>
<div>
</div>
<div>
// }</div>
<div>
delay(50);</div>
<div>
}</div>
<div>
}</div>
<div>
void establishContact() { //prints A until contact is established.</div>
<div>
while (Serial.available() <= 0) {</div>
<div>
Serial.print('A'); // send a capital A</div>
<div>
delay(300);</div>
<div>
}</div>
<div>
}</div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6427771080561552950.post-9065476421813113842015-12-22T16:20:00.002-08:002015-12-22T16:20:27.080-08:00Arduino Drum Kit (Kind of)int force0; //force for pins A0-A3<br />int force1;<br />int force2;<br />int force3;<br />int forcePin0 = 0; //define pins A0-A3<br />int forcePin1 = 1;<br />int forcePin2 = 2;<br />int forcePin3 = 3;<br /><br /><br /><br />void setup() {<br /> pinMode(8, OUTPUT); //Pin for the buzzer<br /> Serial.begin(9600);<br />}<br /><br />void loop() {<br /> force0 = analogRead(forcePin0); //setting forces equal to the readings from pins A0-A3<br /> force1 = analogRead(forcePin1);<br /> force2 = analogRead(forcePin2);<br /> force3 = analogRead(forcePin3);<br /><br /><br /> if (force0 > 50) //If the force sensitive resistor reads greater than 50<br /> {<br /> tone(8, 10, 200); //Then play this tobe<br /> delay(100); //delay breaks tone up to make it sound like a quick repetive tap<br /> //instead of simply a tone. This gives it a more drum-y sound<br /> }<br /> else if (force1 > 50)<br /> {<br /> tone(8, 20000, 500);<br /> delay(100);<br /> }<br /> else if (force2 > 50)<br /> {<br /> tone(8, 90, 20);<br /> delay(100);<br /> }<br /> else if (force3 > 50)<br /> {<br /> tone(8, 20, 200);<br /> delay(100);<br /> }<br /> else<br /> {<br /> noTone(8);<br /> }<br /><br />}Unknownnoreply@blogger.com0