Sparkfun USB weather board

This example is for Wiring version 0027+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.

Serial Output by BARRAGAN

Demonstrates how to send data using the serial port. A computer running a Processing program receives the data from the serial port and fills a rectangle according to the value received.

int switchpin = 0;            // switch connected to pin 0

void setup() {
  pinMode(switchpin, INPUT);  // pin 0 as INPUT
  Serial.begin(9600);         // start serial communication at 9600bps

void loop() {
  if(digitalRead(switchpin) == HIGH)  // if switch is ON
    Serial.print(1, BYTE);            // send 1 to Processing
    Serial.print(0, BYTE);            // otherwise send 0 to Processing
  delay(100);                         // wait 100ms for next print

/* Processing code for this example

// switch serial
// by BARRAGAN <>

// Demonstrates how to read data from the Wiring board, in order 
// to fill a rectangle on the screen using a lighter color when a switch
// connected to the Wiring I/O board is pressed, and fill it with darker
// color when the switch is released.

// created 13 May 2004
// revised 11 September 2010

import processing.serial.*;

Serial port;  // create serial port object
int val;      // variable to receive data from the serial port

void setup() 
  size(200, 200);

  // List all the available serial ports in the output pane.
  // You will need to choose the port that the Wiring board is 
  // connected to from this list. The first port in the list is
  // port #0 and the third port in the list is port #2.

  // Open the port that the Wiring board is connected to (in this case #2)
  // Make sure to open the port at the same speed Wiring is using (9600bps)
  port = new Serial(this, Serial.list()[2], 9600);

void draw() 
  if( 0 < port.available() )  // if data is available to read
    val =;        // read it and store it in 'val'
  background(#222222);        // clear background
  if( val == 0 )              // if 0 was received
    fill(#666660);            // set fill color
    fill(#CCCCC0);            // set fill to a different color
  rect(50, 50, 100, 100);     // draw square