Loading...
「ツール」は右上に移動しました。
利用したサーバー: wtserver2
3いいね 416回再生

Arduino - Interacting with Hardware via Serial Port - Part 2

For this part of the lab, we animate a user-created graphic animation on the computer from data that is received on the serial port from the Arduino. We are using a potentiometer and a LED on a prototyping board wired up to the Arduino UNO. As we change the brightness of the LED on the Arduino, it sends the brightness data to the computer via the serial port. We are using the program Processing to interpret the data and animate the graphic, in this case, the graphic is a virtual LED that changes brightness to simulate the brightness of the actual LED.

Here is the code to draw the LED:
// inByte is a variable mapped to the serial port.
float inByte = float(inString);

// here inByte is mapped to the input. It converts 0 to 1023 to 50 to 255.
// The color red accepts values from 0 to 255, we are using this to
// change the intensity of the red on the virtual LED below. I set the low
// threshold to 50, because when the physical LED is off, it still appears red.
inByte = map(inByte, 0, 1023, 50, 255);

// Draw an LED on the screen
// inner part of leads
stroke(120);
fill(150);
rect(120, 150, 20, 40);
triangle(140, 190, 140, 150, 170, 150);
triangle(150, 190, 180, 150, 180, 190);

// Leads
rect(120, 190, 10, 150);
rect(170, 190, 10, 170);

// Change color brightness of the LED based on the serial value (0-255)
stroke(inByte, 0, 0, 100);
fill(inByte, 0, 0, 100);

// Top part of LED
ellipse(150, 100, 100, 80);
rect(100, 100, 100, 100);

// Bottom part
rect(95, 200, 110, 10);


Audio: www.danosongs.com/ "Matiere Noire Vibrante" - Fingerstyle with Synthesizer

コメント