1. The document provides code examples for controlling an LED using an Arduino board in both C and Arduino IDE languages.
2. The Arduino IDE example blinks an LED connected to pin 13 on and off with a one second delay between states.
3. The C example similarly blinks an LED but requires initializing the microcontroller clock and pins, and uses direct port register access to set the pin high or low.
89. Gainer
1
var lastState = -1; //
var t = 127; //
var h = 20; //
var gio = new Gainer();
function loop():void {
var state = lastState;
var val = gio.analogInput[0]; // 0
if (val < (t - h)) //
state = 0; // 0
else if (val > (t + h)) //
state = 1; // 1
if (lastState == 0 && state == 1) // 0 1
sound.start(); //
lastState = state; //
}
90. Funnel
2
var gio = new Gainer();
//
gio.addFilter(new SetPoint(0.5, 0.1));
//
gio.addEventListener(RISING_EDGE, onButtonPress);
//
function onButtonPress(e:Event):void {
sound.start(); //
}
127. 9 I/O LED
public function GainerLED() {
...
var circle:Sprite = new Sprite();
...
this.addChild(circle);
circle.addEventListener(MouseEvent.MOUSE_DOWN, mousePressed);
circle.addEventListener(MouseEvent.MOUSE_UP, mouseReleased);
}
private function mousePressed(e:MouseEvent):void {
gio.led.value = 1;
}
private function mouseReleased(e:MouseEvent):void {
gio.led.value = 0;
}
128. 10 I/O LED LED button.fla
public function GainerLED() {
gio = new Gainer();
gio.button.addEventListener(PinEvent.RISING_EDGE, buttonPressed);
gio.button.addEventListener(PinEvent.FALLING_EDGE, buttonReleased);
}
private function buttonPressed(e:PinEvent):void {
gio.led.value = 1;
}
private function buttonReleased(e:PinEvent):void {
gio.led.value = 0;
}
156. Arduino LED
11 Arduino LED
int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
157. C LED
12 C LED
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/delay.h>
#define CLK_CALIB_DATA (FLASHEND - 3)
void init() {
uint8_t osccal_data = pgm_read_byte(CLK_CALIB_DATA);
if (osccal_data != 0xff) OSCCAL = osccal_data;
DDRB = 0xff;
DDRD = 0xff;
return;
}
158. C LED
13 C LED
void delay_ms(uint16_t t) {
while (t--) _delay_ms(1);
}
int main(void) {
init();
for (; ;) {
PORTB = 0xff;
delay_ms(500);
PORTB = 0x00;
delay_ms(500);
}
return 0;
}
162. Firmata PC
• Pd (aka Pure Data)
• Processing
• Funnel
• Linux C++
• C++/openFrameworks
163. 10G
IEEE 802.11n
100M
IEEE 802.11a/g
10M IEEE 802.11b
Bluetooth
1M
ANT
100k
ZigBee/IEEE 802.15.4
10k
1k
0.1m 1m 10m 100m 1km
BAN PAN LAN MAN
164. Wi-Fi Bluetooth 802.15.4/ZigBee
IEEE 802.11a/b/g/n 802.15.1 802.15.4
2.4GHz/5GHz 2.4GHz 866MHz/915MHz/2.4GHz
100m 100m 100m 2.4GHz
300Mbps 3Mbps 250kbps 2.4GHz
32 7 65535
LAN
1
171. XBee
XBee
• hardware/fio/tool/XBeeConfigTool
•
• PAN ID
•
• MY ID
• Configure
172. FIO
• XBee Explorer USB PC
• Arduino 16
• Tools Board Arduino Pro/ Pro Mini
(8MHz)
• Tools Serial Port
• Open Examples Digital Blink
• Upload to I/O Board