Brick-Big LED

From ArduinoInfo
Jump to navigation Jump to search

Brick Big LED


This creates a Processing Sketch on the PC that displays a big colorful "LED" on the screen that follows the pin 13 LED on an Arduino.

ARDUINO SKETCH (Copy / paste into New Arduino IDE window). upload to Arduino


/* YourDuinoStarter Example: YD_Big_LED_ToProcessing
 - WHAT IT DOES: Sends 1 or 0 over Serial to Processing Sketch
   See: YD_BigLED Processing Sketch
 - SEE the comments after "//" on each line below

   - 
 - V1.01 03/24/2015
   Questions: terry@yourduino.com */

/*-----( Declare Constants and Pin Numbers )-----*/
#define LED_PIN  13  //The onboard LED

void setup()   /****** SETUP: RUNS ONCE ******/
{
  pinMode(LED_PIN, OUTPUT); // initialize digital pin 13 as an output.
  Serial.begin(9600);  // To send to PC
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  digitalWrite(LED_PIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  Serial.println("1");       // Send to Processing 
  delay(500);              // wait for a second
  Serial.println("0");       // send to processing
  digitalWrite(LED_PIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);              // wait for a second

}//--(end main loop )---

//*********( THE END )***********




PROCESSING SKETCH (Copy / paste into New Processing IDE window).

You need to install the free "Processing" IDE on your computer. See: https://processing.org/download/ You will see that it looks almost like Arduino! That's because Arduino was based on Processing. Copy and paste the Processing sketch below into the Processing IDE and run it.
Make sure you edit this sketch to put in the COM port your Arduino is using!

/* YourDuinoStarter Example: YD_LED - WHAT IT DOES: Creates big on-screen LED that follows the Pin 13 LED on a connected Arduino - SEE the comments after "//" on each line below - V1.01 10/24/2015 Questions: terry@yourduino.com */ /*-----( Import needed libraries )-----*/ import processing.serial.*; /*-----( Declare Constants and Pin Numbers )-----*/ int windowSize = 200; // Change this as you wish int origin = windowSize / 2; int ellipseSize = windowSize - 20; // leave a little margin // Colors are in Hexadecimal format: #RRGGBB int bgcolor = #007FFF; // 0 Red, 1/2 Green, 100% Blue int LED_ON = #FF0000; // Red int LED_OFF = #202020; // Dark Grey /*-----( Declare objects )-----*/ Serial arduinoPort; // Create Serial object /*-----( Declare Variables )-----*/ int charReceived ; void setup() /****** SETUP: RUNS ONCE ******/ { println("These are the serial ports on this computer now:"); println(Serial.list()); // List all the serial ports to the lower window println("Edit your Arduino COM port name into the 'new Serial' line"); /*************( SET SECOND PARAMETER TO YOUR WORKING COM PORT )********************/ arduinoPort = new Serial(this, "COM47", 9600); // Same baud rate as Arduino /*-----( Set up size of display window, background color )----*/ size(windowSize, windowSize); // Windows size in Pixels: X,Y background(bgcolor); ellipse(origin, origin, ellipseSize, ellipseSize); }//--(end setup )--- void draw() /****** LOOP: RUNS CONSTANTLY ******/ { /*---- ( Receive Serial data )-------*/ if ( arduinoPort.available() > 0) // Data is in buffer { charReceived = arduinoPort.read(); // read it and store it ellipse(origin, origin, ellipseSize, ellipseSize); if (charReceived == '1') { fill(LED_ON); } if (charReceived == '0') { fill(LED_OFF); } } // END IF Data Available } //--(end draw )--- /*-----( Declare User-written Functions )-----*/ // None Yet //*********( THE END )***********