2012-10-12 19:23:48 +02:00
|
|
|
/*
|
|
|
|
Arduino Starter Kit example
|
2017-07-15 00:30:34 +02:00
|
|
|
Project 14 - Tweak the Arduino Logo
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2017-07-14 21:34:00 +02:00
|
|
|
This sketch is written to accompany Project 14 in the Arduino Starter Kit
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2017-07-15 00:30:34 +02:00
|
|
|
Parts required:
|
2017-07-12 22:18:23 +02:00
|
|
|
- 10 kilohm potentiometer
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2017-07-12 22:18:23 +02:00
|
|
|
Software required:
|
|
|
|
- Processing (3.0 or newer) http://processing.org
|
|
|
|
- Active Internet connection
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2017-07-12 22:18:23 +02:00
|
|
|
created 18 Sep 2012
|
2017-07-15 00:30:34 +02:00
|
|
|
by Scott Fitzgerald
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2017-07-15 00:30:34 +02:00
|
|
|
http://www.arduino.cc/starterKit
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2017-07-12 22:18:23 +02:00
|
|
|
This example code is part of the public domain.
|
2017-07-15 00:35:58 +02:00
|
|
|
*/
|
2012-10-12 19:23:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
// initialize serial communication
|
|
|
|
Serial.begin(9600);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2017-07-14 21:34:00 +02:00
|
|
|
// read the value of A0, divide by 4 and send it as a byte over the
|
|
|
|
// serial connection
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.write(analogRead(A0) / 4);
|
2012-10-12 19:23:48 +02:00
|
|
|
delay(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Processing code for this example
|
2017-07-15 02:54:32 +02:00
|
|
|
|
2017-07-15 00:30:34 +02:00
|
|
|
// Tweak the Arduino Logo
|
2017-07-15 02:54:32 +02:00
|
|
|
|
2017-07-15 00:30:34 +02:00
|
|
|
// by Scott Fitzgerald
|
2017-07-12 22:18:23 +02:00
|
|
|
// This example code is in the public domain.
|
2017-07-15 00:30:34 +02:00
|
|
|
|
|
|
|
// import the serial library
|
|
|
|
import processing.serial.*;
|
|
|
|
|
|
|
|
// create an instance of the serial library
|
|
|
|
Serial myPort;
|
|
|
|
|
|
|
|
// create an instance of PImage
|
|
|
|
PImage logo;
|
|
|
|
|
|
|
|
// a variable to hold the background color
|
|
|
|
int bgcolor = 0;
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
size(1, 1);
|
|
|
|
surface.setResizable(true);
|
|
|
|
// set the color mode to Hue/Saturation/Brightness
|
|
|
|
colorMode(HSB, 255);
|
|
|
|
|
|
|
|
// load the Arduino logo into the PImage instance
|
|
|
|
logo = loadImage("http://www.arduino.cc/arduino_logo.png");
|
|
|
|
|
|
|
|
// make the window the same size as the image
|
|
|
|
surface.setSize(logo.width, logo.height);
|
|
|
|
|
2017-07-14 21:34:00 +02:00
|
|
|
// print a list of available serial ports to the Processing status window
|
2017-07-15 00:30:34 +02:00
|
|
|
println("Available serial ports:");
|
|
|
|
println(Serial.list());
|
|
|
|
|
2017-07-14 21:34:00 +02:00
|
|
|
// Tell the serial object the information it needs to communicate with the
|
|
|
|
// Arduino. Change Serial.list()[0] to the correct port corresponding to
|
|
|
|
// your Arduino board. The last parameter (e.g. 9600) is the speed of the
|
|
|
|
// communication. It has to correspond to the value passed to
|
|
|
|
// Serial.begin() in your Arduino sketch.
|
2017-07-15 00:30:34 +02:00
|
|
|
myPort = new Serial(this, Serial.list()[0], 9600);
|
|
|
|
|
2017-07-14 21:34:00 +02:00
|
|
|
// If you know the name of the port used by the Arduino board, you can
|
|
|
|
// specify it directly like this.
|
2017-07-15 00:30:34 +02:00
|
|
|
// port = new Serial(this, "COM1", 9600);
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2017-07-15 00:30:34 +02:00
|
|
|
void draw() {
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2017-07-15 00:30:34 +02:00
|
|
|
// if there is information in the serial port
|
|
|
|
if ( myPort.available() > 0) {
|
|
|
|
// read the value and store it in a variable
|
|
|
|
bgcolor = myPort.read();
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2017-07-15 00:30:34 +02:00
|
|
|
// print the value to the status window
|
|
|
|
println(bgcolor);
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2017-07-14 21:34:00 +02:00
|
|
|
// Draw the background. the variable bgcolor contains the Hue, determined by
|
|
|
|
// the value from the serial port
|
2017-07-15 00:30:34 +02:00
|
|
|
background(bgcolor, 255, 255);
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2017-07-15 00:30:34 +02:00
|
|
|
// draw the Arduino logo
|
|
|
|
image(logo, 0, 0);
|
2015-10-22 12:38:01 +02:00
|
|
|
}
|
2017-07-15 02:54:32 +02:00
|
|
|
|
2017-07-15 00:35:58 +02:00
|
|
|
*/
|