2014年12月29日 星期一
2014年12月15日 星期一
2014年12月8日 星期一
Week13_楊育維_01160093
1. 利用 Serial (USB 的 Serial) 來將Arduino的按鍵、旋鈕, 得到輸入值, 都傳給電腦做處理
2. 利用 Serial (USB 的 Serial) 來由電腦 控制 Arduino 的輸出
http://www.arduino.cc/en/Tutorial/InputPullupSerial
http://www.arduino.cc/en/Tutorial/sweep
它可以教你什麼是 ↓
http://arduino.cc/en/pmwiki.php?n=Serial/Print
簡化版
Serial.print() 指令
接下來, 將按鈕 (pin2) 按下去就 ILoveYou, 沒按就 IDon'tLoveYou
皮卡丘打排球
week13
ardunio 接 馬達 & 按鈕
回傳byte程式
void setup()
{
Serial.begin(9600);
}
void loop()
{
while(Serial.available()>0)
{
int data = Serial.read();
Serial.print(data);
}
}
用int的話會輸出ASCII
如果將int 改成 char 則會傳出字元
void setup()
{
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
}
void loop()
{
while(Serial.available()>0)
{
char data = Serial.read();
Serial.print(data);
}
if(digitalRead(2)==LOW) Serial.println("WWW");
else Serial.println("Q_Q");
}
添加按鈕後,按下可交換輸出字樣。
week13
void setup(){
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
}
void loop(){
while(Serial.available()>0){
char data =Serial.read();
//Serial.print(data);
}
if(digitalRead(2)==LOW) Serial.println("LOVE");
else Serial.println("NO");
}
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
}
void loop(){
while(Serial.available()>0){
char data =Serial.read();
//Serial.print(data);
}
if(digitalRead(2)==LOW) Serial.println("LOVE");
else Serial.println("NO");
}
Week13
我做什麼arduino就做什麼
{
Serial.begin(9600);
}
void loop()
{
while(Serial.available()>0)
{
char data=Serial.read();
Serial.print(data);
}
}
按鈕案一下變I Love You
{
Serial.begin(9600);
pinMode(2,INPUT_PULLUP);
}
void loop()
{
while(Serial.available()>0)
{
char data=Serial.read();
Serial.print(data);
}
if(digitalRead(2)==LOW)
Serial.println("I Love You");
else
Serial.println("I Don't Love You");
}
第十三周課堂作業
馬達
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
按按鈕回傳反應
void setup(){
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
}
void loop(){
while (Serial.available()>0) {
char data = Serial.read();
Serial.print(data);
}
if(digitalRead(2)==LOW)Serial.println("I Love You");
else Serial.println("I Don't Love You");
}
Week13
-------------------------------↓↓按按鈕回傳反應↓↓-------------------------------
(電腦反應)
void setup(){
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
}
void loop(){
while (Serial.available()>0) {
char data = Serial.read();
Serial.print(data);
}
if(digitalRead(2)==LOW)Serial.println("I Love You");
else Serial.println("I Don't Love You");
}
-------------------------------↓↓馬達馬達↓↓-------------------------------
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
week13
void setup(){
Serial.begin(9600);
}
void loop(){
while(Serial.available() > 0){
char data = Serial.read();
Serial.print(data);
}
}
Serial.begin(9600);
}
void loop(){
while(Serial.available() > 0){
char data = Serial.read();
Serial.print(data);
}
}
Week13課堂作業
1. 利用 Serial (USB 的 Serial) 來將Arduino的按鍵、旋鈕, 得到輸入值, 都傳給電腦做處理
接下來, 將按鈕 (pin2) 按下去Hello, 沒按HI
Serial.print() 指令
接下來, 將按鈕 (pin2) 按下去Hello, 沒按HI
2. 利用 Serial (USB 的 Serial) 來由電腦 控制 Arduino 的輸出
按按鈕
void setup(){
Serial.begin(9600);
pinMode(2,INPUT_PULLUP);
}
void loop(){
while(Serial.available()>0){
char data=Serial.read();
Serial.print(data);
}
if(digitalRead(2)==LOW)Serial.println("ILoveYou");
else Serial.println("IMissYou");
}
Serial.begin(9600);
pinMode(2,INPUT_PULLUP);
}
void loop(){
while(Serial.available()>0){
char data=Serial.read();
Serial.print(data);
}
if(digitalRead(2)==LOW)Serial.println("ILoveYou");
else Serial.println("IMissYou");
}
訂閱:
文章 (Atom)











































