flash將在自家完成
因此在課堂上並不會製作flash的部分
接下來是我們這禮拜繪製的flash與arduino搭配 製作與運作流程
Arduino利用第29頁的概念,插三個OR四個並聯再一起,即可製成我們所想要的電路,搭配上
這段程式碼(待修改的serproxy)#define bufferSize 16
#define greenLedPin 12
#define redLedPin 13
void setup() {
pinMode(greenLedPin, OUTPUT); // declare the greenLedPin as an OUTPUT
pinMode(redLedPin, OUTPUT); // declare the redLedPin as an OUTPUT
Serial.begin(115200);
}
void loop() {
while (Serial.available() > 0) {
char inBuffer[bufferSize];
int stringLength;
stringLength = Serial.readBytesUntil('\0', inBuffer, bufferSize);
if (stringLength > 0) {
inBuffer[stringLength] = '\0';
String inString = String(inBuffer);
Serial.println(inString);
if ( inString == "G:1" ) {
digitalWrite(greenLedPin, HIGH);
} else if ( inString == "G:0" ) {
digitalWrite(greenLedPin, LOW);
} else if ( inString == "R:1" ) {
digitalWrite(redLedPin, HIGH);
} else if ( inString == "R:0" ) {
digitalWrite(redLedPin, LOW);
}
}
}
}
與這段button的程式碼
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
結合
就能做出我們想要的arduino與flash的融合
透過arduino的控制
我們的flash就能動作。
流程大致上是這樣
參考資料:
http://playground.arduino.cc/interfacing/flash
http://gsyan888.blogspot.tw/2013/05/arduino-serproxy-flash.html
沒有留言:
張貼留言