Commit 51b80acf authored by Katie Isard's avatar Katie Isard
Browse files

week15 video and photo of led and final board

parent e7d2d125
Pipeline #241805 passed with stage
in 16 seconds
......@@ -482,13 +482,111 @@
<p>As seen above I used Luiz's board which is incorrect as this is not a board that I have made myself. I therefore got my final board and had a go with this and it worked yay! I couldn't for some reason get the led ont he bpard to light up via pin 13 but managed to get it to work by using pin 8 and attaching an led on a breadboard and a resistor. It didn't come up very bright but I am very pleased it did work as I was worried I had broken the board again.</p>
<p>
<img src="images/week15/wk15_led.jpeg" height="500" alt="redledoff">
<img src="images/week15/wk15_led.jpeg" height="500" alt="wk15_led">
</p>
<h3>Video of it working</h3>
<video height="500" controls>
<source src="wk15_led.mp4" type="video/mp4">
</video>
<p>
<img src="images/week15/wk15_arduino.jpeg" height="500" alt="wk15_arduino">
</p>
<h3>Processing sketch (this goes first) </h3>
<pre>
import processing.serial.*;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
void setup()
{
size(200, 200);
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw() {
background(255);
if (mouseOverRect() == true) { // If mouse is over square,
fill(204); // change color and
myPort.write('H'); // send an H to indicate mouse is over square
}
else { // If mouse is not over square,
fill(0); // change color and
myPort.write('L'); // send an L otherwise
}
rect(50, 50, 100, 100); // Draw a square
}
boolean mouseOverRect() { // Test if mouse is over square
return ((mouseX >= 50) && (mouseX <= 150) && (mouseY >= 50) && (mouseY <= 150));
}
/*
// Wiring/Arduino code:
// Read data from the serial and turn ON or OFF a light depending on the value
char val; // Data received from the serial port
int ledPin = 4; // Set the pin to digital I/O 4
void setup() {
pinMode(ledPin, OUTPUT); // Set pin as OUTPUT
Serial.begin(9600); // Start serial communication at 9600 bps
}
void loop() {
while (Serial.available()) { // If data is available to read,
val = Serial.read(); // read it and store it in val
}
if (val == 'H') { // If H was received
digitalWrite(ledPin, HIGH); // turn the LED on
} else {
digitalWrite(ledPin, LOW); // Otherwise turn it OFF
}
delay(100); // Wait 100 milliseconds for next reading
}
</pre>
<h3>Arduino sketch (this goes second)</h3>
<pre>
char val; // Data received from the serial port
int ledPin = 8; // Set the pin to digital I/O 4
void setup() {
pinMode(ledPin, OUTPUT); // Set pin as OUTPUT
Serial.begin(9600); // Start serial communication at 9600 bps
}
void loop() {
while (Serial.available()) { // If data is available to read,
val = Serial.read(); // read it and store it in val
}
if (val == 'H') { // If H was received
digitalWrite(ledPin, HIGH); // turn the LED on
} else {
digitalWrite(ledPin, LOW); // Otherwise turn it OFF
}
delay(100); // Wait 100 milliseconds for next reading
}
</pre>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment