1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-13 23:48:46 +01:00
Arduino/build/shared/examples/10.StarterKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino

105 lines
2.4 KiB
Arduino
Raw Normal View History

2012-10-12 19:23:48 +02:00
/*
Arduino Starter Kit example
Project 14 - Tweak the Arduino Logo
2012-10-12 19:23:48 +02:00
This sketch is written to accompany Project 14 in the
Arduino Starter Kit
2012-10-12 19:23:48 +02:00
Parts required:
10 kilohm potentiometer
Software required :
2012-10-12 19:23:48 +02:00
Processing http://processing.org
Active internet connection
2012-10-12 19:23:48 +02:00
Created 18 September 2012
by Scott Fitzgerald
2012-10-12 19:23:48 +02:00
http://arduino.cc/starterKit
This example code is part of the public domain
2012-10-12 19:23:48 +02:00
*/
void setup() {
// initialize serial communication
Serial.begin(9600);
}
void loop() {
// read the value of A0, divide by 4 and
2012-10-12 19:23:48 +02:00
// send it as a byte over the serial connection
Serial.write(analogRead(A0) / 4);
2012-10-12 19:23:48 +02:00
delay(1);
}
/* Processing code for this example
// Tweak the Arduno Logo
// by Scott Fitzgerald
// This example code is in the public domain
2012-10-12 19:23:48 +02:00
// import the serial library
import processing.serial.*;
2012-10-12 19:23:48 +02:00
// create an instance of the serial library
Serial myPort;
2012-10-12 19:23:48 +02:00
// create an instance of PImage
PImage logo;
2012-10-12 19:23:48 +02:00
// a variable to hold the background color
int bgcolor = 0;
2012-10-12 19:23:48 +02:00
void setup() {
// set the color mode to Hue/Saturation/Brightness
colorMode(HSB, 255);
2012-10-12 19:23:48 +02:00
// load the Arduino logo into the PImage instance
logo = loadImage("http://arduino.cc/en/pub/skins/arduinoWide/img/logo.png");
2012-10-12 19:23:48 +02:00
// make the window the same size as the image
size(logo.width, logo.height);
// print a list of available serial ports to the
2012-10-12 19:23:48 +02:00
// Processing staus window
println("Available serial ports:");
println(Serial.list());
2012-10-12 19:23:48 +02:00
// Tell the serial object the information it needs to communicate
// with the Arduno. Change Serial.list()[0] to the correct
2012-10-12 19:23:48 +02:00
// 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.
2012-10-12 19:23:48 +02:00
myPort = new Serial(this, Serial.list()[0], 9600);
2012-10-12 19:23:48 +02:00
// If you know the name of the port used by the Arduino board, you
// can specify it directly like this.
// port = new Serial(this, "COM1", 9600);
2012-10-12 19:23:48 +02:00
}
2012-10-12 19:23:48 +02:00
void draw() {
2012-10-12 19:23:48 +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();
2012-10-12 19:23:48 +02:00
// print the value to the status window
println(bgcolor);
2012-10-12 19:23:48 +02:00
}
2012-10-12 19:23:48 +02:00
// Draw the background. the variable bgcolor
// contains the Hue, determined by the value
// from the serial port
background(bgcolor, 255, 255);
2012-10-12 19:23:48 +02:00
// draw the Arduino logo
image(logo, 0, 0);
}
2012-10-12 19:23:48 +02:00
*/