Debian Codegraph @

examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino

raw
1 /*
2 Arduino Starter Kit example
3 Project 14 - Tweak the Arduino Logo
4
5 This sketch is written to accompany Project 14 in the Arduino Starter Kit
6
7 Parts required:
8 - 10 kilohm potentiometer
9
10 Software required:
11 - Processing (3.0 or newer) https://processing.org/
12 - Active Internet connection
13
14 created 18 Sep 2012
15 by Scott Fitzgerald
16
17 https://store.arduino.cc/genuino-starter-kit
18
19 This example code is part of the public domain.
20 */
21
22
23 void setup() {
24 // initialize serial communication
25 Serial.begin(9600);
26 }
27
28 void loop() {
29 // read the value of A0, divide by 4 and send it as a byte over the
30 // serial connection
31 Serial.write(analogRead(A0) / 4);
32 delay(1);
33 }
34
35 /* Processing code for this example
36
37 // Tweak the Arduino Logo
38
39 // by Scott Fitzgerald
40 // This example code is in the public domain.
41
42 // import the serial library
43 import processing.serial.*;
44
45 // create an instance of the serial library
46 Serial myPort;
47
48 // create an instance of PImage
49 PImage logo;
50
51 // a variable to hold the background color
52 int bgcolor = 0;
53
54 void setup() {
55 size(1, 1);
56 surface.setResizable(true);
57 // set the color mode to Hue/Saturation/Brightness
58 colorMode(HSB, 255);
59
60 // load the Arduino logo into the PImage instance
61 logo = loadImage("http://www.arduino.cc/arduino_logo.png");
62
63 // make the window the same size as the image
64 surface.setSize(logo.width, logo.height);
65
66 // print a list of available serial ports to the Processing status window
67 println("Available serial ports:");
68 println(Serial.list());
69
70 // Tell the serial object the information it needs to communicate with the
71 // Arduino. Change Serial.list()[0] to the correct port corresponding to
72 // your Arduino board. The last parameter (e.g. 9600) is the speed of the
73 // communication. It has to correspond to the value passed to
74 // Serial.begin() in your Arduino sketch.
75 myPort = new Serial(this, Serial.list()[0], 9600);
76
77 // If you know the name of the port used by the Arduino board, you can
78 // specify it directly like this.
79 // port = new Serial(this, "COM1", 9600);
80 }
81
82 void draw() {
83
84 // if there is information in the serial port
85 if ( myPort.available() > 0) {
86 // read the value and store it in a variable
87 bgcolor = myPort.read();
88
89 // print the value to the status window
90 println(bgcolor);
91 }
92
93 // Draw the background. the variable bgcolor contains the Hue, determined by
94 // the value from the serial port
95 background(bgcolor, 255, 255);
96
97 // draw the Arduino logo
98 image(logo, 0, 0);
99 }
100
101 */