Content tagged with button

Arduino Tutorial: Read Button and Send Data to PC


/* Basic Digital Read
* ------------------
*
* turns on and off a light emitting diode(LED) connected to digital
* pin 13, when pressing a pushbutton attached to pin 7. It illustrates the
* concept of Active-Low, which consists in connecting buttons using a
* 1K to 10K pull-up resistor.
*
* Created 1 December 2005
* copyleft 2005 DojoDave
* http://arduino.berlios.de
*
*/

/* Sean Dockray added three lines to demonstrate sending button presses in to a PC! */

int ledPin = 13; // choose the pin for the LED
int inPin = 7; // choose the input pin (for a pushbutton)

Categories: | | |

Processing tutorial: Read button presses from Arduino

import processing.serial.*;

Serial port; // The serial port

void setup() {
size(200, 200);
println(Serial.list()); // list all available serial ports
port = new Serial(this, Serial.list()[2], 19200); // initialize serial communication
}

void draw() {
background(0);
while (port.available() > 0) { // while there are bytes available to read from the serial port
int inByte = port.read(); // read the byte
if (inByte==0) {
fill(255);
rect(width/4,height/4,width/2,height/2);
}
}
}

Categories: | | | |