希德宥XDY
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # homerun [架構](https://www.instructables.com/MESOMIX-Automated-Paint-Mixing-Machine/) [採買清單](https://docs.google.com/spreadsheets/d/1W92vVjgYpxAHwhfL3RxYXUUigrk4m-8GouR7BfJi8IY/edit?usp=sharing) ## 顏料抽取方式 http://www.taichi-maker.com/homepage/reference-index/motor-reference-index/arduino-cnc-shield/ https://www.airspayce.com/mikem/arduino/AccelStepper/classAccelStepper.html [elapsedMillis下載](https://www.arduinolibraries.info/libraries/elapsed-millis) ## 兩個arduino通訊 1.Arduino通訊協議教學 – DevicePlus https://micro.rohm.com/tw/deviceplus/how-tos/arduino-guide/arduino-communication-protocols-tutorial/ 2.Arduino | 序列練習(1):兩個Arduino通訊---使用TX0、RX0 https://hugheschung.blogspot.com/2018/05/arduino-1arduino-tx0rx0.html 3.藍芽 https://swf.com.tw/?p=750 ## 顏色感測器 https://www.youtube.com/watch?v=csTQbmTgGIs shopee:https://shopee.tw/WS2812B-8%E4%BD%8D%E7%9B%B4%E6%A2%9D-RGB%E6%A8%A1%E7%B5%84-%E6%95%B8%E4%BD%8D%E8%A8%8A%E8%99%9F-%E9%9B%BB%E7%AB%B6%E9%A2%A8%E6%94%B9%E8%A3%9D-%E6%99%BA%E6%85%A7%E7%87%88%E5%85%89%E8%A8%AD%E8%A8%88-256%E8%89%B2-WS2812-LED%E7%87%88%E6%A2%9D-i.656213378.14450489913?sp_atk=4b3e9225-8fc5-4571-bf0e-4bfa558d7237&xptdk=4b3e9225-8fc5-4571-bf0e-4bfa558d7237 ### 光敏電阻 1. 連結 [[Arduino範例] 光敏電阻的使用](https://blog.jmaker.com.tw/arduino-photoresistor/) 2. 程式碼 ```cpp= void setup() { Serial.begin(9600); pinMode(3,OUTPUT); } void loop() { int sensorValue = analogRead(A0); Serial.println(sensorValue); if(sensorValue < 900){ //當光敏電阻給的值小於基準值。這個基準值依個別情況修改 digitalWrite(3,HIGH); //燈亮 }else{ digitalWrite(3,LOW); //燈滅 } delay(10); } ``` ## 蝦皮商城 [iCShop](https://shopee.tw/icshop_store) [宇倉電子](https://shopee.tw/allen_6833) [link text](https://shopee.tw/goodsforyou2015) ## 購物清單 | 項目 | 數量 | 單價 | 總價 | | ------------- | ---- | ---- | ---- | | 細管子 | 1 | 0 | 0 | | CNC Shield V3 | 1 | 49 | 49 | | A4988 | 4 | 35 | 140 | | 馬達 | 4 | 375 | 1500 | | 電源供應器 | 1 | 349 | 349 | | 插頭 | 1 | 30 | 30 | | m3x14螺絲 | 2 | 24 | 48 | | m4x20螺絲 | 1 | 35 | 35 | | m4x25螺絲 | 1 | 37 | 37 | | m3螺帽 | 40 | 1 | 40 | | m4螺帽 | 44 | 1 | 44 | | 624軸承 | 24 | 15 | 360 | | 總價 | | | 2632 | 1. 細管子 2. 針筒 3. 馬達*4 4. a4988*4 5. 螺桿(螺絲)、螺帽 6. 馬達聯軸器 7. CNC Shield V3 ```cpp= #include <AccelStepper.h> //本示例程序使用AccelStepper库 #include <elapsedMillis.h> // 定义电机控制用常量 const int enablePin = 8; // 使能控制引脚 // A4988连接Arduino引脚号 const int xdirPin = 5; // 方向控制引脚 const int xstepPin = 2; // 步进控制引脚 const int ydirPin = 6; // y方向控制引脚 const int ystepPin = 3; // y步进控制引脚 const int zdirPin = 7; // z方向控制引脚 const int zstepPin = 4; // z步进控制引脚 const int adirPin = 13; // a方向控制引脚 const int astepPin = 12; // a步进控制引脚 AccelStepper stepper1(1, xstepPin, xdirPin); //建立步进电机对象 AccelStepper stepper2(1, ystepPin, ydirPin); //建立步进电机对象 AccelStepper stepper3(1, zstepPin, zdirPin); //建立步进电机对象 AccelStepper stepper4(1, astepPin, adirPin); //建立步进电机对象 elapsedMillis ptime = 0; void setup() { Serial.begin(115200); pinMode(enablePin, OUTPUT); // Arduino控制A4988使能引脚为输出模式 pinMode(xstepPin, OUTPUT); // Arduino控制A4988步进引脚为输出模式 pinMode(xdirPin, OUTPUT); // Arduino控制A4988方向引脚为输出模式 pinMode(ystepPin, OUTPUT); // Arduino控制A4988步进引脚为输出模式 pinMode(ydirPin, OUTPUT); // Arduino控制A4988方向引脚为输出模式 pinMode(zstepPin, OUTPUT); // Arduino控制A4988步进引脚为输出模式 pinMode(zdirPin, OUTPUT); // Arduino控制A4988方向引脚为输出模式 pinMode(astepPin, OUTPUT); // Arduino控制A4988步进引脚为输出模式 pinMode(adirPin, OUTPUT); // Arduino控制A4988方向引脚为输出模式 digitalWrite(enablePin, LOW); // 将使能控制引脚设置为低电平从而让 digitalWrite(xdirPin, LOW); // 将使能控制引脚设置为低电平从而让 // 电机驱动板进入工作状态 stepper1.setMaxSpeed(300.0); // 设置电机最大速度300 stepper1.setSpeed(100.0); stepper2.setMaxSpeed(300.0); // 设置电机最大速度300 stepper2.setSpeed(0.0); stepper3.setMaxSpeed(300.0); // 设置电机最大速度300 stepper3.setSpeed(0.0); stepper4.setMaxSpeed(300.0); // 设置电机最大速度300 stepper4.setSpeed(0.0); // stepper1.setAcceleration(20.0); 设置电机加速度20.0 } int step1 = 0; bool dir1 = 0; void loop() { // 控制步进电机往复运动 if (ptime >= 1000) { Serial.print(stepper1.currentPosition()); Serial.println(' '); if(dir1==0){ digitalWrite(xdirPin, HIGH); dir1=1; } else{ digitalWrite(xdirPin, LOW); dir1=0; } ptime = 0; } stepper1.runSpeed(); // 1号电机运行 stepper2.runSpeed(); // 1号电机运行 stepper3.runSpeed(); // 1号电机运行 stepper4.runSpeed(); // 1号电机运行 } ``` ```cpp= #include <AccelStepper.h> //本示例程序使用AccelStepper库 #include <elapsedMillis.h> // 定义电机控制用常量 const int enablePin = 8; // 使能控制引脚 // A4988连接Arduino引脚号 const int xdirPin = 5; // 方向控制引脚 const int xstepPin = 2; // 步进控制引脚 const int ydirPin = 6; // y方向控制引脚 const int ystepPin = 3; // y步进控制引脚 const int zdirPin = 7; // z方向控制引脚 const int zstepPin = 4; // z步进控制引脚 const int adirPin = 13; // a方向控制引脚 const int astepPin = 12; // a步进控制引脚 AccelStepper stepper1(1, xstepPin, xdirPin); //建立步进电机对象 AccelStepper stepper2(1, ystepPin, ydirPin); //建立步进电机对象 AccelStepper stepper3(1, zstepPin, zdirPin); //建立步进电机对象 AccelStepper stepper4(1, astepPin, adirPin); //建立步进电机对象 elapsedMillis ptime = 0; void setup() { Serial.begin(115200); pinMode(enablePin, OUTPUT); // Arduino控制A4988使能引脚为输出模式 pinMode(xstepPin, OUTPUT); // Arduino控制A4988步进引脚为输出模式 pinMode(xdirPin, OUTPUT); // Arduino控制A4988方向引脚为输出模式 pinMode(ystepPin, OUTPUT); // Arduino控制A4988步进引脚为输出模式 pinMode(ydirPin, OUTPUT); // Arduino控制A4988方向引脚为输出模式 pinMode(zstepPin, OUTPUT); // Arduino控制A4988步进引脚为输出模式 pinMode(zdirPin, OUTPUT); // Arduino控制A4988方向引脚为输出模式 pinMode(astepPin, OUTPUT); // Arduino控制A4988步进引脚为输出模式 pinMode(adirPin, OUTPUT); // Arduino控制A4988方向引脚为输出模式 digitalWrite(enablePin, LOW); // 将使能控制引脚设置为低电平从而让 // 电机驱动板进入工作状态 stepper1.setMaxSpeed(300.0); // 设置电机最大速度300 stepper1.setSpeed(150.0); stepper2.setMaxSpeed(300.0); // 设置电机最大速度300 stepper2.setSpeed(0.0); stepper3.setMaxSpeed(300.0); // 设置电机最大速度300 stepper3.setSpeed(0.0); stepper4.setMaxSpeed(300.0); // 设置电机最大速度300 stepper4.setSpeed(0.0); // stepper1.setAcceleration(20.0); 设置电机加速度20.0 } int step1 = 0; void loop() { // 控制步进电机往复运动 // if (ptime >= 1000){ // Serial.print(stepper1.currentPosition()); // Serial.print(' '); // Serial.print(stepper2.currentPosition()); // Serial.print(' '); // Serial.println(stepper3.currentPosition()); // ptime=0; // } if(stepper1.currentPosition()>=200){ stepper1.setSpeed(0.0); stepper1.setCurrentPosition(0); stepper2.setSpeed(150.0); } if(stepper2.currentPosition()>=200){ stepper2.setSpeed(0.0); stepper2.setCurrentPosition(0); stepper3.setSpeed(150.0); } if(stepper3.currentPosition()>=200){ stepper3.setSpeed(0.0); stepper3.setCurrentPosition(0); stepper4.setSpeed(150.0); } if(stepper4.currentPosition()>=200){ stepper4.setSpeed(0.0); stepper4.setCurrentPosition(0); stepper1.setSpeed(150.0); } stepper1.runSpeed(); // 1号电机运行 stepper2.runSpeed(); // 1号电机运行 stepper3.runSpeed(); // 1号电机运行 stepper4.runSpeed(); // 1号电机运行 } ``` ```cpp= #include <AccelStepper.h> //本示例程序使用AccelStepper库 // 定义电机控制用常量 const int enablePin = 8; // 使能控制引脚 // A4988连接Arduino引脚号 const int xdirPin = 5; // 方向控制引脚 const int xstepPin = 2; // 步进控制引脚 const int ydirPin = 6; // y方向控制引脚 const int ystepPin = 3; // y步进控制引脚 const int zdirPin = 7; // z方向控制引脚 const int zstepPin = 4; // z步进控制引脚 const int adirPin = 13; // a方向控制引脚 const int astepPin = 12; // a步进控制引脚 AccelStepper stepper1(1, xstepPin, xdirPin); //建立步进电机对象 AccelStepper stepper2(1, ystepPin, ydirPin); //建立步进电机对象 AccelStepper stepper3(1, zstepPin, zdirPin); //建立步进电机对象 AccelStepper stepper4(1, astepPin, adirPin); //建立步进电机对象 //elapsedMillis ptime = 0; void setup() { Serial.begin(115200); pinMode(enablePin, OUTPUT); // Arduino控制A4988使能引脚为输出模式 pinMode(xstepPin, OUTPUT); // Arduino控制A4988步进引脚为输出模式 pinMode(xdirPin, OUTPUT); // Arduino控制A4988方向引脚为输出模式 pinMode(ystepPin, OUTPUT); // Arduino控制A4988步进引脚为输出模式 pinMode(ydirPin, OUTPUT); // Arduino控制A4988方向引脚为输出模式 pinMode(zstepPin, OUTPUT); // Arduino控制A4988步进引脚为输出模式 pinMode(zdirPin, OUTPUT); // Arduino控制A4988方向引脚为输出模式 pinMode(astepPin, OUTPUT); // Arduino控制A4988步进引脚为输出模式 pinMode(adirPin, OUTPUT); // Arduino控制A4988方向引脚为输出模式 digitalWrite(enablePin, LOW); // 将使能控制引脚设置为低电平从而让 digitalWrite(xdirPin, LOW); // 将使能控制引脚设置为低电平从而让 // 电机驱动板进入工作状态 stepper1.setMaxSpeed(300.0); // 设置电机最大速度300 stepper1.setSpeed(100.0); stepper2.setMaxSpeed(300.0); // 设置电机最大速度300 stepper2.setSpeed(0.0); stepper3.setMaxSpeed(300.0); // 设置电机最大速度300 stepper3.setSpeed(0.0); stepper4.setMaxSpeed(300.0); // 设置电机最大速度300 stepper4.setSpeed(0.0); // stepper1.setAcceleration(20.0); 设置电机加速度20.0 } int step1 = 0; bool dir1 = 0; void loop() { int r,g,b; char rc,gc,bc; while(!Serial.available()){}; if(Serial.available()){ rc=Serial.read(); r=Serial.parseInt(); gc=Serial.read(); g=Serial.parseInt(); bc=Serial.read(); b=Serial.parseInt(); float R=r/255,G=g/255,B=b/255; float k=1-max(max(R,G),B),c=(1-R-k)/(1-k),m=(1-G-k)/(1-k),y=(1-B-k)/(1-k); Serial.print(rc); Serial.println(r); Serial.print('c'); Serial.println(c); Serial.print(gc); Serial.println(g); Serial.print('m'); Serial.println(m); Serial.print(bc); Serial.println(b); Serial.print('y'); Serial.println(y); Serial.print('k'); Serial.println(k); } // 控制步进电机往复运动 // if (ptime >= 1000) { // Serial.print(stepper1.currentPosition()); // Serial.println(' '); // if(dir1==0){ // digitalWrite(xdirPin, HIGH); // dir1=1; // } // else{ // digitalWrite(xdirPin, LOW); // dir1=0; // } // ptime = 0; // } // stepper1.runSpeed(); // 1号电机运行 // stepper2.runSpeed(); // 1号电机运行 // stepper3.runSpeed(); // 1号电机运行 // stepper4.runSpeed(); // 1号电机运行 } ``` ## 馬達端主程式 ```cpp= #include <AccelStepper.h> // 馬達腳位常數 const int enablePin = 8; // 使能控制引腳 const int xdirPin = 5; // 方向控制引腳 const int xstepPin = 2; // 步進控制引腳 const int ydirPin = 6; // y方向控制引腳 const int ystepPin = 3; // y步進控制引腳 const int zdirPin = 7; // z方向控制引腳 const int zstepPin = 4; // z步進控制引腳 const int adirPin = 13; // a方向控制引腳 const int astepPin = 12; // a步進控制引腳 // 步進馬達變數 AccelStepper stepper1(1, xstepPin, xdirPin); AccelStepper stepper2(1, ystepPin, ydirPin); AccelStepper stepper3(1, zstepPin, zdirPin); AccelStepper stepper4(1, astepPin, adirPin); void setup() { Serial.begin(115200); pinMode(enablePin, OUTPUT); pinMode(xstepPin, OUTPUT); pinMode(xdirPin, OUTPUT); pinMode(ystepPin, OUTPUT); pinMode(ydirPin, OUTPUT); pinMode(zstepPin, OUTPUT); pinMode(zdirPin, OUTPUT); pinMode(astepPin, OUTPUT); pinMode(adirPin, OUTPUT); digitalWrite(enablePin, LOW); //將控制引腳設為低電位 // 設置馬達最大速度300、初始速度0 stepper1.setMaxSpeed(300.0); stepper1.setSpeed(0.0); stepper2.setMaxSpeed(300.0); stepper2.setSpeed(0.0); stepper3.setMaxSpeed(300.0); stepper3.setSpeed(0.0); stepper4.setMaxSpeed(300.0); stepper4.setSpeed(0.0); } double motorspeed = -150.0; bool getsi = 0; int circ, cirm, ciry, cirk; void loop() { int r, g, b, s; char rc, gc, bc, pc, sc; // 接收主端數值 while (!Serial.available()) {}; if (Serial.available()) { rc = Serial.read(); r = Serial.parseInt(); gc = Serial.read(); g = Serial.parseInt(); bc = Serial.read(); b = Serial.parseInt(); sc = Serial.read(); s = Serial.parseInt(); if (s == 1) getsi = 1; // rgb轉cmyk double R = r * 1.0 / 255.0, G = g * 1.0 / 255.0, B = b * 1.0 / 255.0; double M = max(max(R, G), B); double k = 1.0 - M, c = 1.0 - R * 1.0 / M, m = 1.0 - G * 1.0 / M, y = 1.0 - B * 1.0 / M; c *= 100.0; m *= 100.0; y *= 100.0; k *= 100.0; // 輸出數值 Serial.println("rgb code:"); Serial.print("r: "); Serial.print(rc); Serial.println(r); Serial.print("g: "); Serial.print(gc); Serial.println(g); Serial.print("b: "); Serial.print(bc); Serial.println(b); Serial.println("cmyk code:"); Serial.print("c: "); Serial.println(c); Serial.print("m: "); Serial.println(m); Serial.print("y: "); Serial.println(y); Serial.print("k: "); Serial.println(k); Serial.println(); // 馬達運轉 if (getsi == 1) { double sum = c + y + m + k; circ = c * 20.0 / sum; cirm = m * 20.0 / sum; ciry = y * 20.0 / sum; cirk = k * 20.0 / sum; stepper1.setCurrentPosition(0); while (stepper1.currentPosition() >= -200 * circ) { stepper1.setSpeed(motorspeed); stepper1.runSpeed(); } stepper1.setSpeed(0.0); stepper2.setCurrentPosition(0); while (stepper2.currentPosition() >= -200 * cirm) { stepper2.setSpeed(motorspeed); stepper2.runSpeed(); } stepper2.setSpeed(0.0); stepper3.setCurrentPosition(0); while (stepper3.currentPosition() >= -200 * ciry) { stepper3.setSpeed(motorspeed); stepper3.runSpeed(); } stepper3.setSpeed(0.0); stepper4.setCurrentPosition(0); while (stepper4.currentPosition() >= -200 * cirk) { stepper4.setSpeed(motorspeed); stepper4.runSpeed(); } stepper4.setSpeed(0.0); } getsi = 0; } } ``` ## 感應器端主程式 ```cpp= #include <FastLED.h> #define NUM_LEDS 1 //燈條數量 6顆燈 #define DATA_PIN 7 //燈條腳位 CRGB leds[NUM_LEDS]; CRGB ledshow[NUM_LEDS]; //存入顏色的陣列 int Red[1]; int Green[1]; int Blue[1]; int lightTime = 100; //點亮LED的時間 //設定6顆燈RGB的黑白基準值 int whiteR[1]; int whiteG[1]; int whiteB[1]; int blackR[1]; int blackG[1]; int blackB[1]; void setup() { Serial.begin(115200); LEDS.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS); LEDS.addLeds<WS2812B, 8, RGB>(ledshow, NUM_LEDS); FastLED.setBrightness(255); pinMode(2, INPUT_PULLUP); //黑色基準值的按鈕 pinMode(3, INPUT_PULLUP); //白色基準值的按鈕 pinMode(4, INPUT_PULLUP); //顏色館子校正 pinMode(5, INPUT_PULLUP); //顏色印出 } void loop() { //如果白色基準值的按鈕壓下去 if (digitalRead(3) == LOW) { //亮燈 將讀取到的數值存入白色基準值 ledG(); delay(lightTime); for (int i = 0; i < NUM_LEDS; i++) whiteG[i] = analogRead(A0); ledR(); delay(lightTime); for (int i = 0; i < NUM_LEDS; i++) whiteR[i] = analogRead(A0); ledB(); delay(lightTime); for (int i = 0; i < NUM_LEDS; i++) whiteB[i] = analogRead(A0); delay(lightTime); } //如果黑色基準值的按鈕壓下去 if (digitalRead(2) == LOW) { //亮燈 將讀取到的數值存入黑色基準值 ledG(); delay(lightTime); for (int i = 0; i < NUM_LEDS; i++) blackG[i] = analogRead(A0); ledR(); delay(lightTime); for (int i = 0; i < NUM_LEDS; i++) blackR[i] = analogRead(A0); ledB(); delay(lightTime); for (int i = 0; i < NUM_LEDS; i++) blackB[i] = analogRead(A0); delay(lightTime); } ledR(); delay(lightTime); for (int i = 0; i < NUM_LEDS; i++) Red[i] = constrain( map(analogRead(A0), whiteR[i], blackR[i], 255, 0), 0, 255); ledG(); delay(lightTime); for (int i = 0; i < NUM_LEDS; i++) Green[i] = constrain( map(analogRead(A0), whiteG[i], blackG[i] , 255, 0), 0, 255); ledB(); delay(lightTime); for (int i = 0; i < NUM_LEDS; i++) Blue[i] = constrain( map(analogRead(A0) , whiteB[i], blackB[i], 255, 0), 0, 255); ledOFF(); //關燈 delay(500); Serial.print('r'); Serial.print(Red[0]); Serial.print('g'); Serial.print(Blue[0]); Serial.print('b'); Serial.print(Green[0]); Serial.print('s'); if (digitalRead(5) == LOW){ Serial.print(1); } else Serial.print(0); delay(500); // float r=Red[0]/255,g=Green[0]/255,b=Blue[0]/255; //float k=1-max(max(r,g),b),c=(1-r-k)/(1-k),m=(1-g-k)/(1-k),y=(1-b-k)/(1-k); } //顯示綠色燈 void ledG() { for (int i = 0; i < NUM_LEDS; i++) { leds[i] = CRGB(255, 0, 0); } FastLED.show(); } //顯示紅色燈 void ledR() { for (int i = 0; i < NUM_LEDS; i++) { leds[i] = CRGB(0, 255, 0); } FastLED.show(); } //顯示藍色燈 void ledB() { for (int i = 0; i < NUM_LEDS; i++) { leds[i] = CRGB(0, 0, 255); } FastLED.show(); } //關燈 void ledOFF() { for (int i = 0; i < NUM_LEDS; i++) { leds[i] = CRGB(0, 0, 0); } FastLED.show(); } ``` ## 馬達調整 ```cpp= #include <AccelStepper.h> //本示例程序使用AccelStepper库 #include <elapsedMillis.h> // 定义电机控制用常量 int circ, cirm, ciry, cirk; const int enablePin = 8; // 使能控制引脚 const int xdirPin = 5; // 方向控制引脚 const int xstepPin = 2; // 步进控制引脚 const int ydirPin = 6; // y方向控制引脚 const int ystepPin = 3; // y步进控制引脚 const int zdirPin = 7; // z方向控制引脚 const int zstepPin = 4; // z步进控制引脚 const int adirPin = 13; // a方向控制引脚 const int astepPin = 12; // a步进控制引脚 AccelStepper stepper1(1, xstepPin, xdirPin); //建立步进电机对象 AccelStepper stepper2(1, ystepPin, ydirPin); //建立步进电机对象 AccelStepper stepper3(1, zstepPin, zdirPin); //建立步进电机对象 AccelStepper stepper4(1, astepPin, adirPin); //建立步进电机对象 elapsedMillis ptime = 0; void setup() { Serial.begin(115200); pinMode(enablePin, OUTPUT); // Arduino控制A4988使能引脚为输出模式 pinMode(xstepPin, OUTPUT); // Arduino控制A4988步进引脚为输出模式 pinMode(xdirPin, OUTPUT); // Arduino控制A4988方向引脚为输出模式 pinMode(ystepPin, OUTPUT); // Arduino控制A4988步进引脚为输出模式 pinMode(ydirPin, OUTPUT); // Arduino控制A4988方向引脚为输出模式 pinMode(zstepPin, OUTPUT); // Arduino控制A4988步进引脚为输出模式 pinMode(zdirPin, OUTPUT); // Arduino控制A4988方向引脚为输出模式 pinMode(astepPin, OUTPUT); // Arduino控制A4988步进引脚为输出模式 pinMode(adirPin, OUTPUT); // Arduino控制A4988方向引脚为输出模式 digitalWrite(enablePin, LOW); // 将使能控制引脚设置为低电平从而让 // 电机驱动板进入工作状态 stepper1.setMaxSpeed(300.0); // 设置电机最大速度300 stepper1.setSpeed(0.0); stepper2.setMaxSpeed(300.0); // 设置电机最大速度300 stepper2.setSpeed(0.0); stepper3.setMaxSpeed(300.0); // 设置电机最大速度300 stepper3.setSpeed(0.0); stepper4.setMaxSpeed(300.0); // 设置电机最大速度300 stepper4.setSpeed(0.0); // stepper1.setAcceleration(20.0); 设置电机加速度20.0 } int step1 = 0; bool getsi = 0; void loop() { int cir=Serial.parseInt(); stepper1.setCurrentPosition(0); if(cir>0){ while(stepper1.currentPosition() <= 200*cir){ stepper1.setSpeed(150.0); stepper1.runSpeed(); } } else{ while(stepper1.currentPosition() >=200*cir){ stepper1.setSpeed(-150.0); stepper1.runSpeed(); } } stepper1.setSpeed(0.0); } ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully