顯示具有 Week13 標籤的文章。 顯示所有文章
顯示具有 Week13 標籤的文章。 顯示所有文章

2018年1月22日 星期一

week 13

搖桿換顏色加控制方向

程式教學 
import processing.serial.*;
Serial myPort;

void setup(){
  size(400,400);
  
  myPort=new Serial(this,"COM6",115200);
}

void draw(){

  if(myPort.available()>0){
    //String now = myPort.readString();
    int pin2=myPort.read();
    int x=myPort.read();
    int y=myPort.read();
    println(pin2);
    if(pin2==1) background(255,0,0);
    else background(0,255,0);
    ellipse(x,y,20,20);
  }
}



// Arduino pin numbers
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output

void setup() {
  pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin, HIGH);
  Serial.begin(115200);
}

void loop() {
  Serial.write(digitalRead(2));
  Serial.write(analogRead(A0)/4);
  Serial.write(analogRead(A1)/4);
  //Serial.print(digitalRead(SW_pin));
  //Serial.print("\n");
  //Serial.print("X-axis: ");
  //Serial.print(analogRead(X_pin));
  //Serial.print("\n");
  //Serial.print("Y-axis: ");
 // Serial.println(analogRead(Y_pin));
 // Serial.print("\n\n");
  delay(500);
}
}

2017年12月11日 星期一

Week13 ShiRo

旋轉編碼器(rotary encoder)

網址: https://brainy-bits.com/blogs/tutorials/stepper-motor-rotary-encoder-p1

Rotary Encoder介紹:

CLK : 可讀取DT資料腳位 
SW   : 開關腳位 
+       : 需接正電源 
GND: 接地。

電路:
CLK→腳位2 
DT→腳位3 
SW→腳位4 
+→腳位5v 
GND→腳位GND



引用網址: http://yehnan.blogspot.tw/2014/02/arduino.html



程式碼 :

#define SERIAL_BAUDRATE 115200
#define CLK_PIN 2 // 定義連接腳位
#define DT_PIN 3
#define SW_PIN 4

#define interruptA 0 // UNO腳位2是interrupt 0,其他板子請見官方網頁

volatile long count = 0;
unsigned long t = 0;

void setup() {
  Serial.begin(SERIAL_BAUDRATE);
  // 當狀態下降時,代表旋轉編碼器被轉動了
  attachInterrupt(interruptA, rotaryEncoderChanged, FALLING);
  pinMode(CLK_PIN, INPUT_PULLUP); // 輸入模式並啟用內建上拉電阻
  pinMode(DT_PIN, INPUT_PULLUP); 
  pinMode(SW_PIN, INPUT_PULLUP); 
}
void loop() {
  if(digitalRead(SW_PIN) == LOW){ // 按下開關,歸零
     count = 0;  
     Serial.println("count reset to 0");
     delay(300);
  }
}
void rotaryEncoderChanged(){ // when CLK_PIN is FALLING
  unsigned long temp = millis();
  if(temp - t < 200) // 去彈跳
    return;
  t = temp;
  
  // DT_PIN的狀態代表正轉或逆轉
  count += digitalRead(DT_PIN) == HIGH ? 1 : -1;
  Serial.println(count);
}


使用Python :

做硬體的應用,旋轉rotary encoder,即有圓圈做左右移動互動。



馬達






week13 3D的互動筆記

一、連接Arduino把Rotary Encoder(旋轉編碼器)接上去

1.到https://brainy-bits.com/blogs/tutorials/stepper-motor-rotary-encoder-p1 有旋轉編輯器的電路圖


2.到http://yehnan.blogspot.tw/2014/02/arduino.html 有程式碼以及解說貼上去


3.執行後,旋轉會有數直跑出來(要調115200),按下Arduino板子的按鈕會歸零


4.使用Processing的myPort.readStringUntil(lf)讀取Arduino的訊息


5.讀取訊息來左右移動圓球(需要用切割句子處理讀取所造成的跳行)







Week13 陳柏勳


http://yehnan.blogspot.tw/2014/02/arduino.html(程式碼)
接線---
調baud:115200
轉動旋鈕後數值會跟著增減
processing

import processing.serial.*;
Serial myPort;

void setup(){
  size(500,500);
  myPort=new Serial(this,"COM7",115200);
}
int x=0;
int lf=10;
void draw(){
  background(0);
  if(myPort.available()>0){
    String now = myPort.readStringUntil(lf);
    x=int(split(now,'\r')[0]);
    println(now);
  }
  ellipse(width/2+x*20,height/2,100,100);
}

week13 郭晉瑜上課筆記

360度旋轉編譯器:
https://brainy-bits.com/blogs/tutorials/stepper-motor-rotary-encoder-p1

程式碼:

#define SERIAL_BAUDRATE 115200
#define CLK_PIN 2 // 定義連接腳位
#define DT_PIN 3
#define SW_PIN 4

#define interruptA 0 // UNO腳位2是interrupt 0,其他板子請見官方網頁

volatile long count = 0;
unsigned long t = 0;

void setup() {
  Serial.begin(SERIAL_BAUDRATE);
  // 當狀態下降時,代表旋轉編碼器被轉動了
  attachInterrupt(interruptA, rotaryEncoderChanged, FALLING);
  pinMode(CLK_PIN, INPUT_PULLUP); // 輸入模式並啟用內建上拉電阻
  pinMode(DT_PIN, INPUT_PULLUP); 
  pinMode(SW_PIN, INPUT_PULLUP); 
}
void loop() {
  if(digitalRead(SW_PIN) == LOW){ // 按下開關,歸零
     count = 0;  
     Serial.println("count reset to 0");
     delay(300);
  }
}
void rotaryEncoderChanged(){ // when CLK_PIN is FALLING
  unsigned long temp = millis();
  if(temp - t < 200) // 去彈跳
    return;
  t = temp;
  
  // DT_PIN的狀態代表正轉或逆轉
  count += digitalRead(DT_PIN) == HIGH ? 1 : -1;
  Serial.println(count);
}

成果:


把成果結合在processing視窗下
程式碼:

import processing.serial.*;
Serial myPort;
void setup(){
  size(500,500);
  myPort=new Serial(this,"COM8",115200);
}
int x=0;
int lf=10;
void draw(){
  background(0);
  if(myPort.available()>0){
    String now=myPort.readStringUntil(lf);
    x=int(split(now,'\r')[0]);
    println(now);
  }
  ellipse(width/2+x*20,height/2,100,100);
}

期末作業參考網站:
http://coopermaa2nd.blogspot.tw/2012/11/arduino-starter-kit.html

Week 13 : 普通的ㄒㄆ的普通的筆記

今日目標 :

1. Arduino的物件轉動
2. 馬達


一、旋轉軸加UNO板 & 程式碼
1.



2. 設定Arduino



3. 轉動旋轉軸就可以輸出數字



一、馬達

1. 將馬達連結到UNO板



2.使用範例程式碼



3. 旋轉軸就可以讓馬達震動





第十三週

WEEK13  課堂der筆記筆記

作業一
1.安裝驅動程式,與上周相同
2.

3.程式碼:
#define SERIAL_BAUDRATE 115200
#define CLK_PIN 2 // 定義連接腳位
#define DT_PIN 3
#define SW_PIN 4

#define interruptA 0 // UNO腳位2是interrupt 0,其他板子請見官方網頁

volatile long count = 0;
unsigned long t = 0;

void setup() {
  Serial.begin(SERIAL_BAUDRATE);
  // 當狀態下降時,代表旋轉編碼器被轉動了
  attachInterrupt(interruptA, rotaryEncoderChanged, FALLING);
  pinMode(CLK_PIN, INPUT_PULLUP); // 輸入模式並啟用內建上拉電阻
  pinMode(DT_PIN, INPUT_PULLUP); 
  pinMode(SW_PIN, INPUT_PULLUP); 
}
void loop() {
  if(digitalRead(SW_PIN) == LOW){ // 按下開關,歸零
     count = 0;  
     Serial.println("count reset to 0");
     delay(300);
  }
}
void rotaryEncoderChanged(){ // when CLK_PIN is FALLING
  unsigned long temp = millis();
  if(temp - t < 200) // 去彈跳
    return;
  t = temp;
  
  // DT_PIN的狀態代表正轉或逆轉
  count += digitalRead(DT_PIN) == HIGH ? 1 : -1;
  Serial.println(count);
}



作業二
1.程式碼:
import processing.serial.*;
Serial myPort;

void setup(){
  size(500,500);
  myPort=new Serial(this,"COM6",115200);
}
int x=0;
int lf=10;
void draw(){
  background(0);
  if(myPort.available()>0){
    String now=myPort.readStringUntil(lf);
    x=int (split(now,'\r')[0]);
    println(now);
  }
  ellipse (width/2+x*20,height/2,100,100);
}








week13-紹勳ㄟ上課日記

今天版子出了點問題
後來發現可能是可變電阻插反了
成功圖如下
可以輸入
可變電阻輸入的值了
並且在Proccesses能夠輸入旋鈕的職配合球做左右移動
再控制旋鈕控制馬達

week13

week13 03160801

旋轉編碼器
http://yehnan.blogspot.tw/2014/02/arduino.html



程式碼

#define SERIAL_BAUDRATE 115200
#define CLK_PIN 2 // 定義連接腳位
#define DT_PIN 3
#define SW_PIN 4

#define interruptA 0 // UNO腳位2是interrupt 0,其他板子請見官方網頁

volatile long count = 0;
unsigned long t = 0;

void setup() {
  Serial.begin(SERIAL_BAUDRATE);
  // 當狀態下降時,代表旋轉編碼器被轉動了
  attachInterrupt(interruptA, rotaryEncoderChanged, FALLING);
  pinMode(CLK_PIN, INPUT_PULLUP); // 輸入模式並啟用內建上拉電阻
  pinMode(DT_PIN, INPUT_PULLUP); 
  pinMode(SW_PIN, INPUT_PULLUP); 
}
void loop() {
  if(digitalRead(SW_PIN) == LOW){ // 按下開關,歸零
     count = 0;  
     Serial.println("count reset to 0");
     delay(300);
  }
}
void rotaryEncoderChanged(){ // when CLK_PIN is FALLING
  unsigned long temp = millis();
  if(temp - t < 200) // 去彈跳
    return;
  t = temp;
  
  // DT_PIN的狀態代表正轉或逆轉
  count += digitalRead(DT_PIN) == HIGH ? 1 : -1;
  Serial.println(count);
}


Processing

程式碼

import processing.serial.*;
Serial myPort;

void setup(){
   size(500,500);
   myPort = new Serial(this,"COM8",115200);
}
int x=0;
int lf=10;//new line , line feed
void draw(){
   background(0);
   if(myPort.available() >0){
      String now = myPort.readStringUntil(lf);
      x = int (now);
      println(now + " " + x);
   }
   ellipse(width/2 + x*20, height/2, 100, 100);
   
}



week13

利用旋轉編碼器(rotary encoder)接電路板來控制

參考網址

http://yehnan.blogspot.tw/2014/02/arduino.html

轉動選轉編碼器 
監控器可以看到有數字在跑

找筆記?

week 13
旋鈕
1.按照圖形配置麵包板

2.旋鈕可正轉、逆轉



Week13中澤的上課筆記


一、使用UNO面板來玩Rotary

程式碼:

#define SERIAL_BAUDRATE 115200
#define CLK_PIN 2 // 定義連接腳位
#define DT_PIN 3
#define SW_PIN 4

#define interruptA 0 // UNO腳位2是interrupt 0,其他板子請見官方網頁

volatile long count = 0;
unsigned long t = 0;

void setup() {
  Serial.begin(SERIAL_BAUDRATE);
  // 當狀態下降時,代表旋轉編碼器被轉動了
  attachInterrupt(interruptA, rotaryEncoderChanged, FALLING);
  pinMode(CLK_PIN, INPUT_PULLUP); // 輸入模式並啟用內建上拉電阻
  pinMode(DT_PIN, INPUT_PULLUP); 
  pinMode(SW_PIN, INPUT_PULLUP); 
}
void loop() {
  if(digitalRead(SW_PIN) == LOW){ // 按下開關,歸零
     count = 0;  
     Serial.println("count reset to 0");
     delay(300);
  }
}
void rotaryEncoderChanged(){ // when CLK_PIN is FALLING
  unsigned long temp = millis();
  if(temp - t < 200) // 去彈跳
    return;
  t = temp;
  
  // DT_PIN的狀態代表正轉或逆轉
  count += digitalRead(DT_PIN) == HIGH ? 1 : -1;
  Serial.println(count);
}





二、結合Processing

程式碼:


import processing.serial.*;Serial myPort;void setup(){  size(500,500);  myPort=new Serial(this,"COM8",115200);}int x=0;int lf=10;void draw(){  background(0);  if(myPort.available()>0){    String now=myPort.readStringUntil(lf);    x=int(split(now,'\r')[0]);    println(now);  }  ellipse(width/2+x*20,height/2,100,100);}