Last active
December 24, 2025 11:21
-
-
Save psychemist/b5e25a01ef045e183653da38ef084d74 to your computer and use it in GitHub Desktop.
Arduino Starter Project 14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void setup() { | |
| // open serial connection | |
| Serial.begin(9600); | |
| } | |
| void loop() { | |
| // send sensor value | |
| Serial.write(analogRead(A0) / 4); | |
| // let the ADC stabilize | |
| delay(1); | |
| } | |
| import processing.serial.*; | |
| Serial myPort; | |
| PImage logo; | |
| int bgcolor = 0; | |
| void setup() { | |
| size(1, 1); | |
| surface.setResizable(true); | |
| colorMode(HSB, 255); | |
| // load image LOCALLY (put it in the sketch's data folder) | |
| logo = loadImage("arduino_loop.png"); | |
| if (logo == null) { | |
| println("image failed to load. be real."); | |
| exit(); | |
| } | |
| surface.setSize(logo.width, logo.height); | |
| // list serial ports | |
| println("available serial ports:"); | |
| println(Serial.list()); | |
| // pick the correct port index manually if needed | |
| myPort = new Serial(this, Serial.list()[0], 9600); | |
| myPort.clear(); | |
| } | |
| void draw() { | |
| if (myPort.available() > 0) { | |
| bgcolor = myPort.read() & 0xff; // keep it 0–255 | |
| println(bgcolor); | |
| } | |
| background(bgcolor, 255, 255); | |
| image(logo, 0, 0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment