Components and supplies
Arduino UNO
Project description
Code
uBUG file
arduino
1 2// uBUG Bubble Unik Guillotine 3 4// Helix Fan : Inverted polarities since a drone helix is not a fan ! 5 6#include <Stepper.h> 7#include <Servo.h>// Grid gate operation 8 9#define STEPS_PER_MOTOR_REVOLUTION 32 // Number of steps per revolution of INTERNAL motor in 4-step mode 10#define RevShaft 32 * 64 //2048, steps NB per 1 revolution of OUTPUT SHAFT (= gear reduction; 2048 steps) 11 12Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);// Declare 'small_stepper' variable pins 13Servo GridServo; // create a servo object 14 15//Parameters =================================================== 16 const float topLevelHatchet = 2.0; // : this defines Hatchet elevation level around 2.0 17 18 int HelixOnMilliSec = 900; 19 int MaxMapMtr = 255; //controls Helix speed range. NB MAX = 255 20 21 int OPENGrid = 185; // Grid Angle 22 int CLOSEGrid = 55; // Grid Angle 23//Constants ==================================================== 24 const int SwitchPin = 2; //lateral Switch 25 const int HelixPin = 6; //Helix blower 26 const int potPin = A0;// analog Potentiometer regulates Helix speed 27 const int DOWN = 1; 28 const int UP = -1; 29//Variables ==================================================== 30 int Steps2Take; 31 int SwitchState = 0; 32 33//MAIN ========================================================= 34//MAIN ========================================================= 35void setup() { 36 Serial.begin(9600); 37 38 GridServo.attach(5); // PWM pin required 39 GridServo.write(CLOSEGrid); 40 41// NB NB NB Stepper Library sets pins as outputs NB NB NB 42 pinMode(SwitchPin, INPUT); 43 pinMode(HelixPin, OUTPUT); 44 digitalWrite (HelixPin,LOW); 45 46// To bring Hatchet to bottom reference level with lateral Switch 47 SwitchState = digitalRead(SwitchPin); 48 while (SwitchState == LOW){ 49Serial.print("SwitchState: "); 50Serial.println(SwitchState); 51 Steps2Take = DOWN * RevShaft * 0.0454; 52 small_stepper.setSpeed(1000); 53 small_stepper.step(Steps2Take); 54 SwitchState = digitalRead(SwitchPin); 55 delay(2); 56 }//END while 57 58 delay(200); 59 60 // Small Up step to clear Switch lever : this defines Hatchet bottom level 61 Steps2Take = UP * RevShaft * 0.1; 62 small_stepper.setSpeed(1000); 63 small_stepper.step(Steps2Take); 64 delay(200); 65 66Serial.print("SwitchState after WHILE: "); 67Serial.println(SwitchState); 68}//END setup 69 70void loop() { 71Serial.println("==============================="); 72 // Hatchet emerge from reservoir 73 Steps2Take = UP * RevShaft * topLevelHatchet; //Up 74 small_stepper.setSpeed(1000); 75 small_stepper.step(Steps2Take); 76 77 // Grid OPEN 78 GridServo.write(OPENGrid); 79 delay(400); 80 81 // Helix blows Bubble 82 analogWrite(HelixPin,(fPotControl())); 83 delay(HelixOnMilliSec); 84 digitalWrite (HelixPin,LOW); 85 86// Grid CLOSE 87 delay(200); 88 GridServo.write(CLOSEGrid); 89 90 91 // Hatchet dips into reservoir 92 Steps2Take = DOWN * RevShaft * topLevelHatchet; //Down 93 small_stepper.setSpeed(1000); 94 small_stepper.step(Steps2Take); 95 delay(500); 96 97 }// END loop 98 99// SUBs &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 100int fPotControl(){ // Potentiometer regulates Helix speed 101 int potVal = analogRead(potPin); 102 int mtrVal = map(potVal,0, 1023, 0, MaxMapMtr); // motorVal 103 104Serial.print (potVal); 105Serial.print (" ; "); 106Serial.println (mtrVal); 107 108 return mtrVal; 109}//END sPotControl 110 111
uBUG file
arduino
1 2// uBUG Bubble Unik Guillotine 3 4// Helix Fan : Inverted polarities since a drone helix is not a fan ! 5 6#include <Stepper.h> 7#include <Servo.h>// Grid gate operation 8 9#define STEPS_PER_MOTOR_REVOLUTION 32 // Number of steps per revolution of INTERNAL motor in 4-step mode 10#define RevShaft 32 * 64 //2048, steps NB per 1 revolution of OUTPUT SHAFT (= gear reduction; 2048 steps) 11 12Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);// Declare 'small_stepper' variable pins 13Servo GridServo; // create a servo object 14 15//Parameters =================================================== 16 const float topLevelHatchet = 2.0; // : this defines Hatchet elevation level around 2.0 17 18 int HelixOnMilliSec = 900; 19 int MaxMapMtr = 255; //controls Helix speed range. NB MAX = 255 20 21 int OPENGrid = 185; // Grid Angle 22 int CLOSEGrid = 55; // Grid Angle 23//Constants ==================================================== 24 const int SwitchPin = 2; //lateral Switch 25 const int HelixPin = 6; //Helix blower 26 const int potPin = A0;// analog Potentiometer regulates Helix speed 27 const int DOWN = 1; 28 const int UP = -1; 29//Variables ==================================================== 30 int Steps2Take; 31 int SwitchState = 0; 32 33//MAIN ========================================================= 34//MAIN ========================================================= 35void setup() { 36 Serial.begin(9600); 37 38 GridServo.attach(5); // PWM pin required 39 GridServo.write(CLOSEGrid); 40 41// NB NB NB Stepper Library sets pins as outputs NB NB NB 42 pinMode(SwitchPin, INPUT); 43 pinMode(HelixPin, OUTPUT); 44 digitalWrite (HelixPin,LOW); 45 46// To bring Hatchet to bottom reference level with lateral Switch 47 SwitchState = digitalRead(SwitchPin); 48 while (SwitchState == LOW){ 49Serial.print("SwitchState: "); 50Serial.println(SwitchState); 51 Steps2Take = DOWN * RevShaft * 0.0454; 52 small_stepper.setSpeed(1000); 53 small_stepper.step(Steps2Take); 54 SwitchState = digitalRead(SwitchPin); 55 delay(2); 56 }//END while 57 58 delay(200); 59 60 // Small Up step to clear Switch lever : this defines Hatchet bottom level 61 Steps2Take = UP * RevShaft * 0.1; 62 small_stepper.setSpeed(1000); 63 small_stepper.step(Steps2Take); 64 delay(200); 65 66Serial.print("SwitchState after WHILE: "); 67Serial.println(SwitchState); 68}//END setup 69 70void loop() { 71Serial.println("==============================="); 72 // Hatchet emerge from reservoir 73 Steps2Take = UP * RevShaft * topLevelHatchet; //Up 74 small_stepper.setSpeed(1000); 75 small_stepper.step(Steps2Take); 76 77 // Grid OPEN 78 GridServo.write(OPENGrid); 79 delay(400); 80 81 // Helix blows Bubble 82 analogWrite(HelixPin,(fPotControl())); 83 delay(HelixOnMilliSec); 84 digitalWrite (HelixPin,LOW); 85 86// Grid CLOSE 87 delay(200); 88 GridServo.write(CLOSEGrid); 89 90 91 // Hatchet dips into reservoir 92 Steps2Take = DOWN * RevShaft * topLevelHatchet; //Down 93 small_stepper.setSpeed(1000); 94 small_stepper.step(Steps2Take); 95 delay(500); 96 97 }// END loop 98 99// SUBs &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 100int fPotControl(){ // Potentiometer regulates Helix speed 101 int potVal = analogRead(potPin); 102 int mtrVal = map(potVal,0, 1023, 0, MaxMapMtr); // motorVal 103 104Serial.print (potVal); 105Serial.print (" ; "); 106Serial.println (mtrVal); 107 108 return mtrVal; 109}//END sPotControl 110 111
Downloadable files
uBUG Schematic
uBUG Schematic
Comments
Only logged in users can leave comments
JHG
0 Followers
•0 Projects
Table of contents
Intro
3
0