Last active
December 16, 2015 18:21
-
-
Save benwei/5477365 to your computer and use it in GitHub Desktop.
blink arduino's led (pin 13) by serial input with char 'a'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int led = 13; | |
void setup() | |
{ | |
Serial.begin(9600);//设置波特率为9600bps | |
pinMode(led, OUTPUT); | |
} | |
void turnon_led() { | |
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) | |
delay(1000); // wait for a second | |
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW | |
delay(1000); // wait for a second | |
} | |
void loop () | |
{ | |
if(Serial.available()) | |
{ | |
int lkf = Serial.read(); | |
switch(lkf) | |
{ | |
case 'a': | |
turnon_led(); | |
break; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- vi /www/cgi-bin/web2ser -- prepare new file | |
-- file content below | |
#!/usr/bin/lua | |
io.output("/dev/ttyACM0") -- | |
io.write(os.getenv("QUERY_STRING")) | |
-- after file saved, type command "chmod 755 /www/cgi-bin/web2ser" for correct cgi execute permission |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<div style="float:left"> | |
<script> | |
function sendSer(value){ | |
document.getElementById("ser").src="/cgi-bin/web2ser?"+value; | |
} | |
</script> | |
<table> | |
<tr> | |
<td> | |
<input type="button" onmousedown="sendSer('a')" onmouseup="sendSer('a')" value="blink" /> | |
</td> | |
</tr> | |
</table> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/lua | |
io.output('/dev/ttyACM0') | |
local step = 0; | |
while (step < 5) do | |
io.write('a\r\n') | |
os.execute('sleep 2') | |
step=step+1; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment