소스 검색

Upload files to 'Ardu_code'

Yuechuan_Xu 7 달 전
부모
커밋
fa69c081f5
2개의 변경된 파일232개의 추가작업 그리고 0개의 파일을 삭제
  1. 129 0
      Ardu_code/Arduino_XY.ino
  2. 103 0
      Ardu_code/Arduino_Z.ino

+ 129 - 0
Ardu_code/Arduino_XY.ino

@@ -0,0 +1,129 @@
+#include <Servo.h>
+#include <Wire.h> 
+#include <LiquidCrystal_I2C.h>
+
+/* Declare pins for digital input from the RASPBERRY PI */
+const int x_up_pin = 2;
+const int x_down_pin = 3 ;
+const int y_up_pin = 4;
+const int y_down_pin = 5 ;
+
+/* Declare pins for servo output */
+const int servo_x_Pin = 9; 
+const int servo_y_Pin = 10;
+
+/* Analog input pins for Joystick XY values */
+const int JoyStick_X = 0; // pin number for x
+const int JoyStick_Y = 1; // pin number for y
+
+/* Declare flag pin to send digital output to the RASPBERRY PI */
+const int signal_pin = 12;
+
+/* Declare 2 servo objects to control de degrees of freedom of the XY Stage */
+Servo servo_x;
+Servo servo_y;  
+
+/* Set the LCD address to 0x27 for a 16 chars and 2 lines display */
+LiquidCrystal_I2C lcd(0x27, 16, 2);
+
+/* Set up the default position of the servos: in the middle */
+int servo_x_Angle = 90; 
+int servo_y_Angle = 90;
+
+/* Actuation flag: not moving */
+bool actuating = false;
+int moving_x = 0; 
+int moving_y = 0;  
+
+/* Joystick sensitivity */
+const int threshold = 64;
+
+ 
+void setup() 
+{
+  /* Communicate to the RASPBERRY PI if the Arduino is
+  actuating (the stage is moving) or listening */
+  pinMode(signal_pin, OUTPUT);   // to send 1 bit message to pi
+  digitalWrite(signal_pin, LOW); // not actuating
+
+  /* Prepare the servos */
+  Serial.begin(9600); // 9600 bps
+  servo_x.attach(servo_x_Pin);
+  servo_y.attach(servo_y_Pin);
+
+  /* Prepare the LCD */
+  lcd.begin();
+  /* Turn the blacklight on and print a message */
+  lcd.backlight();
+  lcd.setCursor(0,0);
+  lcd.print("HomeScope");
+  lcd.setCursor(0,1);
+  lcd.print("  by Biotexturas");delay(5000);
+
+  /* Position at the center of the scanning area 
+  (x,y) = (90,90) */
+  servo_x.write(servo_x_Angle); 
+  servo_y.write(servo_y_Angle);  
+
+  /* Set up the RASPBERRY PI communication pins (4 bits) */
+  pinMode(x_up_pin, INPUT);      // GUI button x.step-up
+  pinMode(x_down_pin, INPUT);    // GUI button x.step-down
+  pinMode(y_up_pin, INPUT);      // GUI button y.step-up
+  pinMode(y_down_pin, INPUT);    // GUI button y.step-down
+         
+  delay(50); 
+}
+
+
+void loop() 
+{ 
+  /* X movement (signal detection) */
+  /* X.UP */
+  if ((analogRead(JoyStick_X) > (512 + threshold) && actuating == false) 
+      || (digitalRead(x_up_pin) == HIGH && actuating == false)) 
+        {
+        if(servo_x_Angle < 180) servo_x_Angle++;
+         actuating = true;  
+        }        
+  /* X.DOWN */
+  if ((analogRead(JoyStick_X) < (512 - threshold) && actuating==false) 
+      || (digitalRead(x_down_pin) == HIGH && actuating == false)) 
+        {
+         if(servo_x_Angle > 0)servo_x_Angle--;
+         actuating = true;
+        }
+  /* Y movement (signal detection) */
+  /* Y.UP */
+  if ((analogRead(JoyStick_Y) > (512 + threshold) && actuating==false) 
+      || (digitalRead(y_up_pin) == HIGH && actuating==false)) 
+        {
+         if (servo_y_Angle < 180 ) {servo_y_Angle++;}
+         actuating= true;  
+        }
+  /* Y.DOWN */
+  if ((analogRead(JoyStick_Y) < (512 - threshold) &&  actuating==false) 
+      || (digitalRead(y_down_pin) == HIGH  &&  actuating==false))  
+        {
+         if (servo_y_Angle > 0) {servo_y_Angle--;}
+         actuating = true;
+        }
+        
+  /* Move */
+  if (actuating == true)
+        {  
+         digitalWrite(signal_pin, HIGH);     //  Actuating          
+         servo_x.write(servo_x_Angle); 
+         servo_y.write(servo_y_Angle);        
+         delay(500);
+         actuating = false;
+         digitalWrite(signal_pin, LOW);     // Not actuating
+        }
+  /* Display position info */
+  lcd.setCursor(0,1);
+  lcd.print("position:"); 
+  lcd.print(servo_x_Angle); 
+  lcd.print(",");
+  lcd.print(servo_y_Angle);
+  lcd.print("    ");      
+  delay(50);
+}

+ 103 - 0
Ardu_code/Arduino_Z.ino

@@ -0,0 +1,103 @@
+#define DISTANCE 1  // Define the discrete length of a step
+
+int StepCounter = 0;
+bool Stepping = false;
+
+/* Declare flag pin to send digital output to the RASPBERRY PI */
+const int signal_pin = 12;
+
+const int top_range_pin = 6;
+const int bottom_range_pin = 7;
+
+/* Easy Driver pins */
+const int driver_dir = 8;
+const int driver_stp = 9;
+
+/* Physical buttons */
+const int button_up = 2;
+const int button_down = 3;
+
+/* GUI buttons */
+const int gui_up = 4;
+const int gui_down = 5;
+
+void setup() 
+  {
+
+  /* Report state of automata: listening or stepping? */
+  pinMode(signal_pin, OUTPUT);  
+  digitalWrite(signal_pin, LOW);
+  
+  /* Set range pins as inputs to read range sensors. 
+  Stage will move only if sensors are high */
+  pinMode(top_range_pin, INPUT);
+  pinMode(bottom_range_pin, INPUT);
+  
+  /* Pull up both UP and DOWN range pins */
+  digitalWrite(top_range_pin, HIGH);
+  digitalWrite(bottom_range_pin, HIGH);
+  
+  /* Easy Driver
+  To control direction. Set as LOW for UP direction and HIGH for DOWN direction */
+  pinMode(driver_dir, OUTPUT);
+  /* To step one step */
+  pinMode(driver_stp, OUTPUT); 
+  digitalWrite(driver_dir, LOW);     // Starting direction is UP
+  digitalWrite(driver_stp, LOW);     //  No-step
+
+  /* Up */
+  pinMode(button_up, INPUT);         // physical button step-up
+  pinMode(gui_up, INPUT);            // GUI button step-up
+  
+  /* Down */
+  pinMode(button_down, INPUT);       // physical button step-down
+  pinMode(gui_down, INPUT);          // GUI button step-down
+    
+  }
+
+void loop() 
+  {
+  /* Read range sensors */
+  bool value_top = digitalRead(top_range_pin);
+  bool value_bottom = digitalRead(bottom_range_pin);
+
+  if (!value_top || !value_bottom) 
+    {
+    Serial.println("Stage out of range");
+    }
+
+  /* Check up direction with */
+  if ((digitalRead(button_up) == LOW || digitalRead(gui_up) == HIGH) 
+      && (Stepping == false && value_top))
+    {
+    digitalWrite(driver_dir, LOW);
+    Stepping = true;
+    digitalWrite(signal_pin, HIGH);  
+    }
+    
+  
+  /* Check down direction with */
+  if ((digitalRead(button_down) == LOW || digitalRead(gui_down) == HIGH) 
+      && (Stepping == false && value_bottom))
+    {
+     digitalWrite(driver_dir, HIGH);
+     Stepping = true;
+     digitalWrite(signal_pin, HIGH); 
+    }
+  
+  /* If wished, go ahead and step */
+  if (Stepping == true)
+    {
+    digitalWrite(driver_stp, HIGH);
+    delay(1);
+    digitalWrite(driver_stp, LOW);
+    delay(1);
+    StepCounter += 1;
+    if (StepCounter == DISTANCE)
+       {
+        StepCounter = 0;
+        Stepping = false;
+        digitalWrite(signal_pin, LOW); 
+        }
+    }
+  }