目前我正在尝试制作一个草图,其中 Arduino 将读取一系列字符作为命令,并根据从 iDevice 发送的一系列字符做一些事情。我正在使用越狱的 iPhone 3GS 向 Arduino 发送字符。发送串行字符的方法如下所示,
- (IBAction)blinkFlow_A_LED:(id)sender {
// method to blink the Flow_A LED on the kegboard-mini Arduino sheild.
NSLog(@"blink Flow_A btn pressed");
// open serial port / interface
[serial open:B2400];
NSLog(@"%c", [serial isOpened]);
// send serial data (tx)
char buffer [7];
buffer[0] = '{';
buffer[1] = 'b';
buffer[2] = 'l';
buffer[3] = 'i';
buffer[4] = 'n';
buffer[5] = 'k';
buffer[6] = '}';
[serial write:buffer length:7];
}
我创建了一个简单的草图,它使我正在使用的防护罩上的 LED 闪烁,但我希望 LED 在 iOS 应用程序中单击按钮时有条件地闪烁。闪烁 LED 的草图如下所示,
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This sketch is specific to making the kegboard-mini shield.
http://arduino.cc/forum/index.php?topic=157625.new;topicseen#new
This example code is in the public domain.
*/
// pin D4 - should be connected to the flow_A LED
// give it a name
int led = 4;
// the setup routine runs once when you press reset:
void setup() {
//initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine run over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for one second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}