├── .DS_Store
├── README.md
├── PC_SPEAKER_BEEP
└── PC_SPEAKER_BEEP.ino
├── code1
├── GantryXYZ.h
├── GCODEClasses.h
├── GCODEClasses.cpp
├── code1.ino
├── GantryClasses.h
├── GantryXYZ.cpp
└── GantryClasses.cpp
├── code2
├── GantryXYZ.h
├── GCODEClasses.h
├── GCODEClasses.cpp
├── GantryClasses.h
├── GantryXYZ.cpp
├── code2.ino
└── GantryClasses.cpp
├── code3
├── GantryXYZ.h
├── GCODEClasses.h
├── GCODEClasses.cpp
├── GantryClasses.h
├── GantryXYZ.cpp
├── code3.ino
└── GantryClasses.cpp
├── code4
├── GantryXYZ.h
├── GCODEClasses.h
├── GCODEClasses.cpp
├── GantryClasses.h
├── GantryXYZ.cpp
├── code4.ino
└── GantryClasses.cpp
├── code5
├── GantryXYZ.h
├── GCODEClasses.h
├── GCODEClasses.cpp
├── code5.ino
├── GantryClasses.h
├── GantryXYZ.cpp
└── GantryClasses.cpp
├── stepper_with_limit_test_1
└── stepper_with_limit_test_1.ino
├── HALL_LIMIT_STEPPER
└── HALL_LIMIT_STEPPER.ino
├── HelloNodeMCU_OLED
└── HelloNodeMCU_OLED.ino
├── HelloNodeMCUWifi
└── HelloNodeMCUWifi.ino
├── Tb6560Arduino
└── Tb6560Arduino.ino
├── cdromstepperA4988
└── cdromstepperA4988.ino
├── ROTARY_ENCODER
└── ROTARY_ENCODER.ino
├── JSN-SR04T
└── JSN-SR04T.ino
├── Flowrate
└── Flowrate.ino
├── BYJ48_STEPPER
└── BYJ48_STEPPER.ino
├── NodeMCULEDOnOff
└── NodeMCULEDOnOff.ino
└── OLEDRangeFinder
└── OLEDRangeFinder.ino
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jumejume1/Arduino/HEAD/.DS_Store
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Arduino
2 | Maker Tutor Channel
3 |
4 | This folder contains some Arduino libraries and some code samples.
5 |
6 | For questions - check Arduino's forum
7 |
--------------------------------------------------------------------------------
/PC_SPEAKER_BEEP/PC_SPEAKER_BEEP.ino:
--------------------------------------------------------------------------------
1 | int speakerOut = 9;
2 | void setup() {
3 | // put your setup code here, to run once:
4 | pinMode(speakerOut,OUTPUT);
5 | }
6 |
7 | void loop() {
8 | // put your main code here, to run repeatedly:
9 | beep();
10 | delay(500);
11 | }
12 | void beep(){
13 |
14 | for( int i = 0; i<500;i++){
15 | digitalWrite(speakerOut , HIGH);
16 | delayMicroseconds(500);
17 | digitalWrite(speakerOut, LOW );
18 | delayMicroseconds(500);
19 | }
20 |
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/code1/GantryXYZ.h:
--------------------------------------------------------------------------------
1 | /*
2 | GantryClasses.h
3 |
4 | Author : Jamorn Saksommon
5 | Class
6 | // please see http://www.github.com/MarginallyClever/GcodeCNCDemo for more information.
7 |
8 | Modifly date: 27.01.2017
9 | */
10 |
11 | #ifndef Gantry_XYZ_h
12 | #define Gantry_XYZ_h
13 |
14 | #include "GantryClasses.h"
15 | #include "GCODEClasses.h"
16 |
17 |
18 | class GantryXYZClasses : public GantryClasses , public GCODEClasses
19 | {
20 |
21 | public:
22 |
23 | GantryXYZClasses();
24 |
25 | void processCommand();
26 |
27 | };
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/code2/GantryXYZ.h:
--------------------------------------------------------------------------------
1 | /*
2 | GantryClasses.h
3 |
4 | Author : Jamorn Saksommon
5 | Class
6 | // please see http://www.github.com/MarginallyClever/GcodeCNCDemo for more information.
7 |
8 | Modifly date: 27.01.2017
9 | */
10 |
11 | #ifndef Gantry_XYZ_h
12 | #define Gantry_XYZ_h
13 |
14 | #include "GantryClasses.h"
15 | #include "GCODEClasses.h"
16 |
17 |
18 | class GantryXYZClasses : public GantryClasses , public GCODEClasses
19 | {
20 |
21 | public:
22 |
23 | GantryXYZClasses();
24 |
25 | void processCommand();
26 |
27 | };
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/code3/GantryXYZ.h:
--------------------------------------------------------------------------------
1 | /*
2 | GantryClasses.h
3 |
4 | Author : Jamorn Saksommon
5 | Class
6 | // please see http://www.github.com/MarginallyClever/GcodeCNCDemo for more information.
7 |
8 | Modifly date: 27.01.2017
9 | */
10 |
11 | #ifndef Gantry_XYZ_h
12 | #define Gantry_XYZ_h
13 |
14 | #include "GantryClasses.h"
15 | #include "GCODEClasses.h"
16 |
17 |
18 | class GantryXYZClasses : public GantryClasses , public GCODEClasses
19 | {
20 |
21 | public:
22 |
23 | GantryXYZClasses();
24 |
25 | void processCommand();
26 |
27 | };
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/code4/GantryXYZ.h:
--------------------------------------------------------------------------------
1 | /*
2 | GantryClasses.h
3 |
4 | Author : Jamorn Saksommon
5 | Class
6 | // please see http://www.github.com/MarginallyClever/GcodeCNCDemo for more information.
7 |
8 | Modifly date: 27.01.2017
9 | */
10 |
11 | #ifndef Gantry_XYZ_h
12 | #define Gantry_XYZ_h
13 |
14 | #include "GantryClasses.h"
15 | #include "GCODEClasses.h"
16 |
17 |
18 | class GantryXYZClasses : public GantryClasses , public GCODEClasses
19 | {
20 |
21 | public:
22 |
23 | GantryXYZClasses();
24 |
25 | void processCommand();
26 |
27 | };
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/code5/GantryXYZ.h:
--------------------------------------------------------------------------------
1 | /*
2 | GantryClasses.h
3 |
4 | Author : Jamorn Saksommon
5 | Class
6 | // please see http://www.github.com/MarginallyClever/GcodeCNCDemo for more information.
7 |
8 | Modifly date: 27.01.2017
9 | */
10 |
11 | #ifndef Gantry_XYZ_h
12 | #define Gantry_XYZ_h
13 |
14 | #include "GantryClasses.h"
15 | #include "GCODEClasses.h"
16 |
17 |
18 | class GantryXYZClasses : public GantryClasses , public GCODEClasses
19 | {
20 |
21 | public:
22 |
23 | GantryXYZClasses();
24 |
25 | void processCommand();
26 |
27 | };
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/code1/GCODEClasses.h:
--------------------------------------------------------------------------------
1 | /*
2 | GCODEClasses.h
3 |
4 | Author : Jamorn Saksommon
5 | Class
6 |
7 |
8 | Modifly date: 03.02.2017
9 | */
10 |
11 | #ifndef GCODE_Classes_h
12 | #define GCODE_Classes_h
13 |
14 | #define MAX_BUF (20) // What is the longest message Arduino can store?
15 |
16 | class GCODEClasses
17 | {
18 | public:
19 | char buffer[MAX_BUF];
20 | int sofar;
21 | GCODEClasses();
22 | void storeBuffer( char);
23 | float parsenumber(char code,float val);
24 | void ready();
25 | virtual void processCommand() =0;
26 | };
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/code2/GCODEClasses.h:
--------------------------------------------------------------------------------
1 | /*
2 | GCODEClasses.h
3 |
4 | Author : Jamorn Saksommon
5 | Class
6 |
7 |
8 | Modifly date: 03.02.2017
9 | */
10 |
11 | #ifndef GCODE_Classes_h
12 | #define GCODE_Classes_h
13 |
14 | #define MAX_BUF (20) // What is the longest message Arduino can store?
15 |
16 | class GCODEClasses
17 | {
18 | public:
19 | char buffer[MAX_BUF];
20 | int sofar;
21 | GCODEClasses();
22 | void storeBuffer( char);
23 | float parsenumber(char code,float val);
24 | void ready();
25 | virtual void processCommand() =0;
26 | };
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/code3/GCODEClasses.h:
--------------------------------------------------------------------------------
1 | /*
2 | GCODEClasses.h
3 |
4 | Author : Jamorn Saksommon
5 | Class
6 |
7 |
8 | Modifly date: 03.02.2017
9 | */
10 |
11 | #ifndef GCODE_Classes_h
12 | #define GCODE_Classes_h
13 |
14 | #define MAX_BUF (20) // What is the longest message Arduino can store?
15 |
16 | class GCODEClasses
17 | {
18 | public:
19 | char buffer[MAX_BUF];
20 | int sofar;
21 | GCODEClasses();
22 | void storeBuffer( char);
23 | float parsenumber(char code,float val);
24 | void ready();
25 | virtual void processCommand() =0;
26 | };
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/code4/GCODEClasses.h:
--------------------------------------------------------------------------------
1 | /*
2 | GCODEClasses.h
3 |
4 | Author : Jamorn Saksommon
5 | Class
6 |
7 |
8 | Modifly date: 03.02.2017
9 | */
10 |
11 | #ifndef GCODE_Classes_h
12 | #define GCODE_Classes_h
13 |
14 | #define MAX_BUF (20) // What is the longest message Arduino can store?
15 |
16 | class GCODEClasses
17 | {
18 | public:
19 | char buffer[MAX_BUF];
20 | int sofar;
21 | GCODEClasses();
22 | void storeBuffer( char);
23 | float parsenumber(char code,float val);
24 | void ready();
25 | virtual void processCommand() =0;
26 | };
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/code5/GCODEClasses.h:
--------------------------------------------------------------------------------
1 | /*
2 | GCODEClasses.h
3 |
4 | Author : Jamorn Saksommon
5 | Class
6 |
7 |
8 | Modifly date: 03.02.2017
9 | */
10 |
11 | #ifndef GCODE_Classes_h
12 | #define GCODE_Classes_h
13 |
14 | #define MAX_BUF (20) // What is the longest message Arduino can store?
15 |
16 | class GCODEClasses
17 | {
18 | public:
19 | char buffer[MAX_BUF];
20 | int sofar;
21 | GCODEClasses();
22 | void storeBuffer( char);
23 | float parsenumber(char code,float val);
24 | void ready();
25 | virtual void processCommand() =0;
26 | };
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/stepper_with_limit_test_1/stepper_with_limit_test_1.ino:
--------------------------------------------------------------------------------
1 | // defines pins numbers
2 | const int stepPin = 5;
3 | const int dirPin = 2;
4 | const int enPin = 8;
5 | const int limitPin = 7;
6 | void setup() {
7 |
8 | pinMode(limitPin,INPUT);
9 | // Sets the two pins as Outputs
10 | pinMode(stepPin,OUTPUT);
11 | pinMode(dirPin,OUTPUT);
12 |
13 | pinMode(enPin,OUTPUT);
14 | digitalWrite(enPin,LOW);
15 |
16 | }
17 | void loop() {
18 |
19 | if( digitalRead(limitPin) == HIGH){
20 | digitalWrite(stepPin,HIGH);
21 | delayMicroseconds(500);
22 | digitalWrite(stepPin,LOW);
23 | delayMicroseconds(500);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/HALL_LIMIT_STEPPER/HALL_LIMIT_STEPPER.ino:
--------------------------------------------------------------------------------
1 | // defines pins numbers
2 | const int stepPin = 5;
3 | const int dirPin = 2;
4 | const int enPin = 8;
5 |
6 | const int limitPin = 7;
7 |
8 | void setup() {
9 |
10 | pinMode( limitPin , INPUT);
11 | // Sets the two pins as Outputs
12 | pinMode(stepPin,OUTPUT);
13 | pinMode(dirPin,OUTPUT);
14 |
15 | pinMode(enPin,OUTPUT);
16 | digitalWrite(enPin,LOW);
17 |
18 | }
19 | void loop() {
20 |
21 | digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
22 | // Makes 200 pulses for making one full cycle rotation
23 | if( digitalRead( limitPin) == HIGH )
24 | {
25 | digitalWrite(stepPin,HIGH);
26 | delayMicroseconds(500);
27 | digitalWrite(stepPin,LOW);
28 | delayMicroseconds(500);
29 | }
30 |
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/HelloNodeMCU_OLED/HelloNodeMCU_OLED.ino:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | #define OLED_RESET LED_BUILTIN //4
7 | Adafruit_SSD1306 display(OLED_RESET);
8 |
9 | #if (SSD1306_LCDHEIGHT != 64)
10 | #error("Height incorrect, please fix Adafruit_SSD1306.h!");
11 | #endif
12 |
13 | void setup() {
14 |
15 | display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
16 |
17 | // Clear the buffer.
18 | display.clearDisplay();
19 | display.display();
20 |
21 | display.setTextSize(2);
22 | display.setTextColor(WHITE);
23 |
24 | display.setCursor(0,0);
25 | display.println("Hello NodeMCU & OLED");
26 | display.println("MakerTutor");
27 | display.display();
28 |
29 | }
30 |
31 | void loop() {
32 | // put your main code here, to run repeatedly:
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/code1/GCODEClasses.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | GCODEClasses.cpp
3 |
4 | Author : Jamorn Saksommon
5 | Class
6 |
7 | Modifly date: 03.02.2017
8 | */
9 |
10 | #include
11 | #include "GCODEClasses.h"
12 |
13 |
14 | GCODEClasses::GCODEClasses(){
15 | sofar = 0;
16 | }
17 |
18 | void GCODEClasses::storeBuffer( char c){
19 |
20 | if( c == '\n'){
21 | buffer[sofar]=0;
22 | return;
23 | }
24 |
25 | if(sofar
11 | #include "GCODEClasses.h"
12 |
13 |
14 | GCODEClasses::GCODEClasses(){
15 | sofar = 0;
16 | }
17 |
18 | void GCODEClasses::storeBuffer( char c){
19 |
20 | if( c == '\n'){
21 | buffer[sofar]=0;
22 | return;
23 | }
24 |
25 | if(sofar
11 | #include "GCODEClasses.h"
12 |
13 |
14 | GCODEClasses::GCODEClasses(){
15 | sofar = 0;
16 | }
17 |
18 | void GCODEClasses::storeBuffer( char c){
19 |
20 | if( c == '\n'){
21 | buffer[sofar]=0;
22 | return;
23 | }
24 |
25 | if(sofar
11 | #include "GCODEClasses.h"
12 |
13 |
14 | GCODEClasses::GCODEClasses(){
15 | sofar = 0;
16 | }
17 |
18 | void GCODEClasses::storeBuffer( char c){
19 |
20 | if( c == '\n'){
21 | buffer[sofar]=0;
22 | return;
23 | }
24 |
25 | if(sofar
11 | #include "GCODEClasses.h"
12 |
13 |
14 | GCODEClasses::GCODEClasses(){
15 | sofar = 0;
16 | }
17 |
18 | void GCODEClasses::storeBuffer( char c){
19 |
20 | if( c == '\n'){
21 | buffer[sofar]=0;
22 | return;
23 | }
24 |
25 | if(sofar 0) { // if something is available
17 | char c=Serial.read(); // get it
18 | Serial.print(c); // repeat it back so I know you got the message
19 |
20 | gantryXYZ.storeBuffer( c );
21 |
22 | if(c=='\n') {
23 | // entire message received
24 | gantryXYZ.storeBuffer( c );
25 | Serial.print(F("\r\n")); // echo a return character for humans
26 | gantryXYZ.processCommand(); // do something with the command
27 |
28 | }
29 | }
30 |
31 | gantryXYZ.move();
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/HelloNodeMCUWifi/HelloNodeMCUWifi.ino:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | const char* ssid="Your SSID";
4 | const char* password = "Your Password";
5 |
6 | int ledPin = 13;
7 |
8 | void setup() {
9 |
10 | pinMode(ledPin,OUTPUT);
11 | digitalWrite(ledPin,LOW);
12 |
13 | Serial.begin(115200);
14 | Serial.println();
15 | Serial.print("Wifi connecting to ");
16 | Serial.println( ssid );
17 |
18 | WiFi.begin(ssid,password);
19 |
20 | Serial.println();
21 | Serial.print("Connecting");
22 |
23 | while( WiFi.status() != WL_CONNECTED ){
24 | delay(500);
25 | Serial.print(".");
26 | }
27 |
28 | digitalWrite( ledPin , HIGH);
29 | Serial.println();
30 |
31 | Serial.println("Wifi Connected Success!");
32 | Serial.print("NodeMCU IP Address : ");
33 | Serial.println(WiFi.localIP() );
34 |
35 | }
36 |
37 | void loop() {
38 | // put your main code here, to run repeatedly:
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/Tb6560Arduino/Tb6560Arduino.ino:
--------------------------------------------------------------------------------
1 | // defines pins numbers
2 | const int stepPin = 5;
3 | const int dirPin = 2;
4 | const int enPin = 8;
5 | void setup() {
6 |
7 | // Sets the two pins as Outputs
8 | pinMode(stepPin,OUTPUT);
9 | pinMode(dirPin,OUTPUT);
10 |
11 | pinMode(enPin,OUTPUT);
12 | digitalWrite(enPin,LOW);
13 |
14 | }
15 | void loop() {
16 |
17 | digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
18 | // Makes 200 pulses for making one full cycle rotation
19 | for(int x = 0; x < 800; x++) {
20 | digitalWrite(stepPin,HIGH);
21 | delayMicroseconds(500);
22 | digitalWrite(stepPin,LOW);
23 | delayMicroseconds(500);
24 | }
25 | delay(1000); // One second delay
26 |
27 | digitalWrite(dirPin,LOW); //Changes the rotations direction
28 | // Makes 400 pulses for making two full cycle rotation
29 | for(int x = 0; x < 800; x++) {
30 | digitalWrite(stepPin,HIGH);
31 | delayMicroseconds(500);
32 | digitalWrite(stepPin,LOW);
33 | delayMicroseconds(500);
34 | }
35 | delay(1000);
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/cdromstepperA4988/cdromstepperA4988.ino:
--------------------------------------------------------------------------------
1 | // defines pins numbers
2 | const int stepPin = 5;
3 | const int dirPin = 2;
4 | const int enPin = 8;
5 | void setup() {
6 |
7 | // Sets the two pins as Outputs
8 | pinMode(stepPin,OUTPUT);
9 | pinMode(dirPin,OUTPUT);
10 |
11 | pinMode(enPin,OUTPUT);
12 | digitalWrite(enPin,LOW);
13 |
14 | }
15 | void loop() {
16 |
17 | digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
18 | // Makes 200 pulses for making one full cycle rotation
19 | for(int x = 0; x < 800; x++) {
20 | digitalWrite(stepPin,HIGH);
21 | delayMicroseconds(500);
22 | digitalWrite(stepPin,LOW);
23 | delayMicroseconds(500);
24 | }
25 | delay(1000); // One second delay
26 |
27 | digitalWrite(dirPin,LOW); //Changes the rotations direction
28 | // Makes 400 pulses for making two full cycle rotation
29 | for(int x = 0; x < 800; x++) {
30 | digitalWrite(stepPin,HIGH);
31 | delayMicroseconds(500);
32 | digitalWrite(stepPin,LOW);
33 | delayMicroseconds(500);
34 | }
35 | delay(1000);
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/code5/code5.ino:
--------------------------------------------------------------------------------
1 | #include "GantryXYZ.h"
2 |
3 | GantryXYZClasses gantryXYZ;
4 |
5 | int state = 0;
6 |
7 | void setup() {
8 |
9 | Serial.begin(9600); // Default connection rate for my BT module
10 | gantryXYZ.setFeedrate(1000); // set default speed
11 |
12 | // When Start move to Home
13 | gantryXYZ.prepareMove(-1000,0,0);
14 |
15 | }
16 |
17 | void loop() {
18 |
19 | /*
20 | * Home limit switch Hall Effect sensor normal = 1
21 | * Hit = 0
22 | *
23 | */
24 |
25 | if( !gantryXYZ.is_move){
26 |
27 | state = 0 ;
28 | if(Serial.available() > 0)
29 | state = Serial.read();
30 |
31 | if( state == 50){
32 |
33 | gantryXYZ.prepareMove(-1000,0,0);
34 | }
35 | else if(state == 49){
36 |
37 | gantryXYZ.prepareMove( 400,0,0);
38 | }
39 | }
40 |
41 |
42 | gantryXYZ.move();
43 |
44 |
45 | }
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/ROTARY_ENCODER/ROTARY_ENCODER.ino:
--------------------------------------------------------------------------------
1 | volatile unsigned int temp, counter = 0; //This variable will increase or decrease depending on the rotation of encoder
2 |
3 | void setup() {
4 | Serial.begin (9600);
5 |
6 | pinMode(2, INPUT_PULLUP); // internal pullup input pin 2
7 |
8 | pinMode(3, INPUT_PULLUP); // internalเป็น pullup input pin 3
9 | //Setting up interrupt
10 | //A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr 2 on moust Arduino.
11 | attachInterrupt(0, ai0, RISING);
12 |
13 | //B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr 3 on moust Arduino.
14 | attachInterrupt(1, ai1, RISING);
15 | }
16 |
17 | void loop() {
18 | // Send the value of counter
19 | if( counter != temp ){
20 | Serial.println (counter);
21 | temp = counter;
22 | }
23 | }
24 |
25 | void ai0() {
26 | // ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH
27 | // Check pin 3 to determine the direction
28 | if(digitalRead(3)==LOW) {
29 | counter++;
30 | }else{
31 | counter--;
32 | }
33 | }
34 |
35 | void ai1() {
36 | // ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH
37 | // Check with pin 2 to determine the direction
38 | if(digitalRead(2)==LOW) {
39 | counter--;
40 | }else{
41 | counter++;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/JSN-SR04T/JSN-SR04T.ino:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------------
2 | // Example NewPing library sketch that does a ping about 20 times per second.
3 | // ---------------------------------------------------------------------------
4 |
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
12 | #define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
13 | #define MAX_DISTANCE 450 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
14 |
15 |
16 | NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
17 |
18 | MedianFilter filter(31,0);
19 |
20 | void setup() {
21 |
22 | Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
23 |
24 |
25 |
26 | }
27 |
28 | void loop() {
29 |
30 | delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
31 | unsigned int o,uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
32 |
33 | filter.in(uS);
34 | o = filter.out();
35 | Serial.print("Ping: ");
36 | Serial.print( o / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
37 | Serial.println("cm");
38 |
39 |
40 | }
41 |
42 |
43 |
--------------------------------------------------------------------------------
/Flowrate/Flowrate.ino:
--------------------------------------------------------------------------------
1 |
2 | // reading liquid flow rate using Seeeduino and Water Flow Sensor from Seeedstudio.com
3 | // Code adapted by Charles Gantt from PC Fan RPM code written by Crenn @thebestcasescenario.com
4 | // http:/themakersworkbench.com http://thebestcasescenario.com http://seeedstudio.com
5 |
6 | volatile int NbTopsFan; //measuring the rising edges of the signal
7 | int Calc;
8 | int hallsensor = 2; //The pin location of the sensor
9 |
10 | void rpm () //This is the function that the interupt calls
11 | {
12 | NbTopsFan++; //This function measures the rising and falling edge of the hall effect sensors signal
13 |
14 |
15 | }
16 | // The setup() method runs once, when the sketch starts
17 | void setup() //
18 | {
19 | pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
20 | Serial.begin(9600); //This is the setup function where the serial port is initialised,
21 |
22 |
23 | attachInterrupt(0, rpm, RISING); //and the interrupt is attached
24 | }
25 | // the loop() method runs over and over again,
26 | // as long as the Arduino has power
27 | void loop ()
28 | {
29 | NbTopsFan = 0; //Set NbTops to 0 ready for calculations
30 | sei(); //Enables interrupts
31 | delay (1000); //Wait 1 second
32 | cli(); //Disable interrupts
33 | Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour
34 |
35 |
36 | Serial.print (Calc, DEC); //Prints the number calculated above
37 | Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a new line
38 | }
39 |
--------------------------------------------------------------------------------
/code2/GantryClasses.h:
--------------------------------------------------------------------------------
1 | /*
2 | GantryClasses.h
3 | Class
4 | // please see http://www.github.com/MarginallyClever/GcodeCNCDemo for more information.
5 |
6 | Modifly date: 27.01.2017
7 | */
8 |
9 | #ifndef Gantry_Classes_h
10 | #define Gantry_Classes_h
11 |
12 |
13 | #define STEPS_PER_MM (40)
14 | #define MAX_FEEDRATE (1000000)
15 | #define MIN_FEEDRATE (1)
16 |
17 | #define AXIS_X 0
18 | #define AXIS_Y 1
19 | #define AXIS_Z 2
20 |
21 |
22 | typedef struct {
23 | int step_pin;
24 | int dir_pin;
25 | int enable_pin;
26 | int home_switch_pin;
27 | } Motor;
28 |
29 | // for line()
30 | typedef struct {
31 | long delta; // number of steps to move
32 | long absdelta;
33 | long over; // for dx/dy bresenham calculations
34 | } Axis;
35 |
36 |
37 |
38 | class GantryClasses
39 | {
40 | public:
41 | bool is_move;
42 | uint8_t num_axis;
43 | float feed_rate; // human version
44 | long step_delay;
45 | unsigned long delay_t;
46 | long maxsteps;
47 | long step_count;
48 | long accel;
49 | float px,py,pz,pg;
50 |
51 | long steps_to_accel;
52 | long steps_to_decel;
53 |
54 | unsigned long prev_time;
55 |
56 | char mode_abs; //absolute mode;
57 |
58 | Axis *axis; // for move()
59 | Motor *motors;
60 |
61 | GantryClasses();
62 |
63 | void setFeedrate( float nfr);
64 | void setPosition(float npx,float npy,float npz);
65 | void prepareMove( float newx,float newy,float newz );
66 | void move();
67 |
68 | void disableMotor();
69 | void enableMotor();
70 |
71 | };
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/code5/GantryClasses.h:
--------------------------------------------------------------------------------
1 | /*
2 | GantryClasses.h
3 | Class
4 | // please see http://www.github.com/MarginallyClever/GcodeCNCDemo for more information.
5 |
6 | Modifly date: 27.01.2017
7 | */
8 |
9 | #ifndef Gantry_Classes_h
10 | #define Gantry_Classes_h
11 |
12 |
13 | #define STEPS_PER_MM (40)
14 | #define MAX_FEEDRATE (1000000)
15 | #define MIN_FEEDRATE (1)
16 |
17 | #define AXIS_X 0
18 | #define AXIS_Y 1
19 | #define AXIS_Z 2
20 |
21 |
22 | typedef struct {
23 | int step_pin;
24 | int dir_pin;
25 | int enable_pin;
26 | int home_switch_pin;
27 | } Motor;
28 |
29 | // for line()
30 | typedef struct {
31 | long delta; // number of steps to move
32 | long absdelta;
33 | long over; // for dx/dy bresenham calculations
34 | } Axis;
35 |
36 |
37 |
38 | class GantryClasses
39 | {
40 | public:
41 | bool is_move;
42 | uint8_t num_axis;
43 | float feed_rate; // human version
44 | long step_delay;
45 | unsigned long delay_t;
46 | long maxsteps;
47 | long step_count;
48 | long accel;
49 | float px,py,pz,pg;
50 |
51 | long steps_to_accel;
52 | long steps_to_decel;
53 |
54 | unsigned long prev_time;
55 |
56 | char mode_abs; //absolute mode;
57 |
58 | Axis *axis; // for move()
59 | Motor *motors;
60 |
61 | GantryClasses();
62 |
63 | void setFeedrate( float nfr);
64 | void setPosition(float npx,float npy,float npz);
65 | void prepareMove( float newx,float newy,float newz );
66 | void move();
67 |
68 | void disableMotor();
69 | void enableMotor();
70 |
71 | };
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/code1/GantryClasses.h:
--------------------------------------------------------------------------------
1 | /*
2 | GantryClasses.h
3 | Class
4 | // please see http://www.github.com/MarginallyClever/GcodeCNCDemo for more information.
5 |
6 | Modifly date: 27.01.2017
7 | */
8 |
9 | #ifndef Gantry_Classes_h
10 | #define Gantry_Classes_h
11 |
12 |
13 | #define STEPS_PER_MM (40)
14 | #define MAX_FEEDRATE (1000000)
15 | #define MIN_FEEDRATE (1)
16 |
17 | #define AXIS_X 0
18 | #define AXIS_Y 1
19 | #define AXIS_Z 2
20 |
21 |
22 | typedef struct {
23 | int step_pin;
24 | int dir_pin;
25 | int enable_pin;
26 | int limit_switch_pin;
27 | } Motor;
28 |
29 | // for line()
30 | typedef struct {
31 | long delta; // number of steps to move
32 | long absdelta;
33 | long over; // for dx/dy bresenham calculations
34 | } Axis;
35 |
36 |
37 |
38 | class GantryClasses
39 | {
40 | public:
41 | bool is_move;
42 | uint8_t num_axis;
43 | float feed_rate; // human version
44 | long step_delay;
45 | unsigned long delay_t;
46 | long maxsteps;
47 | long step_count;
48 | long accel;
49 | float px,py,pz,pg;
50 |
51 | long steps_to_accel;
52 | long steps_to_decel;
53 |
54 | unsigned long prev_time;
55 |
56 | char mode_abs; //absolute mode;
57 |
58 | Axis *axis; // for move()
59 | Motor *motors;
60 |
61 | GantryClasses();
62 |
63 | void setFeedrate( float nfr);
64 | void setPosition(float npx,float npy,float npz);
65 | void prepareMove( float newx,float newy,float newz );
66 | void move();
67 |
68 | void disableMotor();
69 | void enableMotor();
70 |
71 | };
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/code3/GantryClasses.h:
--------------------------------------------------------------------------------
1 | /*
2 | GantryClasses.h
3 | Class
4 | // please see http://www.github.com/MarginallyClever/GcodeCNCDemo for more information.
5 |
6 | Modifly date: 27.01.2017
7 | */
8 |
9 | #ifndef Gantry_Classes_h
10 | #define Gantry_Classes_h
11 |
12 |
13 | #define STEPS_PER_MM (40)
14 | #define MAX_FEEDRATE (1000000)
15 | #define MIN_FEEDRATE (1)
16 |
17 | #define AXIS_X 0
18 | #define AXIS_Y 1
19 | #define AXIS_Z 2
20 |
21 |
22 | typedef struct {
23 | int step_pin;
24 | int dir_pin;
25 | int enable_pin;
26 | int home_switch_pin;
27 | } Motor;
28 |
29 | // for line()
30 | typedef struct {
31 | long delta; // number of steps to move
32 | long absdelta;
33 | long over; // for dx/dy bresenham calculations
34 | } Axis;
35 |
36 |
37 |
38 | class GantryClasses
39 | {
40 | public:
41 | bool is_move;
42 | uint8_t num_axis;
43 | float feed_rate; // human version
44 | long step_delay;
45 | unsigned long delay_t;
46 | long maxsteps;
47 | long step_count;
48 | long accel;
49 | float px,py,pz,pg;
50 |
51 | long steps_to_accel;
52 | long steps_to_decel;
53 |
54 | unsigned long prev_time;
55 |
56 | char mode_abs; //absolute mode;
57 |
58 | Axis *axis; // for move()
59 | Motor *motors;
60 |
61 | GantryClasses();
62 |
63 | void setFeedrate( float nfr);
64 | void setPosition(float npx,float npy,float npz);
65 | void prepareMove( float newx,float newy,float newz );
66 | void move(unsigned int _delay);
67 |
68 | void disableMotor();
69 | void enableMotor();
70 |
71 | };
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/code4/GantryClasses.h:
--------------------------------------------------------------------------------
1 | /*
2 | GantryClasses.h
3 | Class
4 | // please see http://www.github.com/MarginallyClever/GcodeCNCDemo for more information.
5 |
6 | Modifly date: 27.01.2017
7 | */
8 |
9 | #ifndef Gantry_Classes_h
10 | #define Gantry_Classes_h
11 |
12 |
13 | #define STEPS_PER_MM (40)
14 | #define MAX_FEEDRATE (1000000)
15 | #define MIN_FEEDRATE (1)
16 |
17 | #define AXIS_X 0
18 | #define AXIS_Y 1
19 | #define AXIS_Z 2
20 |
21 |
22 | typedef struct {
23 | int step_pin;
24 | int dir_pin;
25 | int enable_pin;
26 | int home_switch_pin;
27 | int max_travel;
28 | } Motor;
29 |
30 | // for line()
31 | typedef struct {
32 | long delta; // number of steps to move
33 | long absdelta;
34 | long over; // for dx/dy bresenham calculations
35 | } Axis;
36 |
37 |
38 |
39 | class GantryClasses
40 | {
41 | public:
42 | bool is_move;
43 | uint8_t num_axis;
44 | float feed_rate; // human version
45 | long step_delay;
46 | unsigned long delay_t;
47 | long maxsteps;
48 | long step_count;
49 | long accel;
50 | float px,py,pz,pg;
51 |
52 | long steps_to_accel;
53 | long steps_to_decel;
54 |
55 | unsigned long prev_time;
56 |
57 | char mode_abs; //absolute mode;
58 |
59 | Axis *axis; // for move()
60 | Motor *motors;
61 |
62 | GantryClasses();
63 |
64 | void setFeedrate( float nfr);
65 | void setPosition(float npx,float npy,float npz);
66 | void prepareMove( float newx,float newy,float newz );
67 | void move(unsigned int _delay);
68 |
69 | void disableMotor();
70 | void enableMotor();
71 |
72 | };
73 |
74 | #endif
75 |
--------------------------------------------------------------------------------
/code1/GantryXYZ.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include "GantryXYZ.h"
4 |
5 | GantryXYZClasses::GantryXYZClasses()
6 | {
7 | num_axis = 1;
8 |
9 | motors = new Motor[num_axis];
10 | axis = new Axis[num_axis];
11 |
12 | // X
13 | motors[0].step_pin=5;
14 | motors[0].dir_pin=2;
15 | motors[0].enable_pin=8;
16 | motors[0].limit_switch_pin=7;
17 | /*
18 | // Y
19 | motors[1].step_pin=46;
20 | motors[1].dir_pin=48;
21 | motors[1].enable_pin=62;
22 | motors[1].limit_switch_pin=14;
23 | // Z
24 | motors[2].step_pin=26;
25 | motors[2].dir_pin=28;
26 | motors[2].enable_pin=24;
27 | motors[2].limit_switch_pin=18;
28 |
29 |
30 | */
31 |
32 | for(int i=0;i
3 | #include "GantryXYZ.h"
4 |
5 | GantryXYZClasses::GantryXYZClasses()
6 | {
7 | num_axis = 1;
8 |
9 | motors = new Motor[num_axis];
10 | axis = new Axis[num_axis];
11 |
12 | // X
13 | motors[0].step_pin=5;
14 | motors[0].dir_pin=2;
15 | motors[0].enable_pin=8;
16 | motors[0].home_switch_pin=7;
17 | /*
18 | // Y
19 | motors[1].step_pin=46;
20 | motors[1].dir_pin=48;
21 | motors[1].enable_pin=62;
22 | motors[1].limit_switch_pin=14;
23 | // Z
24 | motors[2].step_pin=26;
25 | motors[2].dir_pin=28;
26 | motors[2].enable_pin=24;
27 | motors[2].limit_switch_pin=18;
28 |
29 |
30 | */
31 |
32 | for(int i=0;i
3 | #include "GantryXYZ.h"
4 |
5 | GantryXYZClasses::GantryXYZClasses()
6 | {
7 | num_axis = 1;
8 |
9 | motors = new Motor[num_axis];
10 | axis = new Axis[num_axis];
11 |
12 | // X
13 | motors[0].step_pin=5;
14 | motors[0].dir_pin=2;
15 | motors[0].enable_pin=8;
16 | motors[0].home_switch_pin=7;
17 | /*
18 | // Y
19 | motors[1].step_pin=46;
20 | motors[1].dir_pin=48;
21 | motors[1].enable_pin=62;
22 | motors[1].limit_switch_pin=14;
23 | // Z
24 | motors[2].step_pin=26;
25 | motors[2].dir_pin=28;
26 | motors[2].enable_pin=24;
27 | motors[2].limit_switch_pin=18;
28 |
29 |
30 | */
31 |
32 | for(int i=0;i
3 | #include "GantryXYZ.h"
4 |
5 | GantryXYZClasses::GantryXYZClasses()
6 | {
7 | num_axis = 1;
8 |
9 | motors = new Motor[num_axis];
10 | axis = new Axis[num_axis];
11 |
12 | // X
13 | motors[0].step_pin=5;
14 | motors[0].dir_pin=2;
15 | motors[0].enable_pin=8;
16 | motors[0].home_switch_pin=7;
17 | /*
18 | // Y
19 | motors[1].step_pin=46;
20 | motors[1].dir_pin=48;
21 | motors[1].enable_pin=62;
22 | motors[1].limit_switch_pin=14;
23 | // Z
24 | motors[2].step_pin=26;
25 | motors[2].dir_pin=28;
26 | motors[2].enable_pin=24;
27 | motors[2].limit_switch_pin=18;
28 |
29 |
30 | */
31 |
32 | for(int i=0;i
3 | #include "GantryXYZ.h"
4 |
5 | GantryXYZClasses::GantryXYZClasses()
6 | {
7 | num_axis = 1;
8 |
9 | motors = new Motor[num_axis];
10 | axis = new Axis[num_axis];
11 |
12 | // X
13 | motors[0].step_pin=5;
14 | motors[0].dir_pin=2;
15 | motors[0].enable_pin=8;
16 | motors[0].home_switch_pin=7;
17 | motors[0].max_travel = 450;
18 | /*
19 | // Y
20 | motors[1].step_pin=46;
21 | motors[1].dir_pin=48;
22 | motors[1].enable_pin=62;
23 | motors[1].limit_switch_pin=14;
24 | // Z
25 | motors[2].step_pin=26;
26 | motors[2].dir_pin=28;
27 | motors[2].enable_pin=24;
28 | motors[2].limit_switch_pin=18;
29 |
30 |
31 | */
32 |
33 | for(int i=0;i 0) { // if something is available
65 | char c=Serial.read(); // get it
66 | Serial.print(c); // repeat it back so I know you got the message
67 |
68 | gantryXYZ.storeBuffer( c );
69 |
70 | if(c=='\n') {
71 | // entire message received
72 | gantryXYZ.storeBuffer( c );
73 | Serial.print(F("\r\n")); // echo a return character for humans
74 | gantryXYZ.processCommand(); // do something with the command
75 |
76 | }
77 | }
78 |
79 |
80 | gantryXYZ.move(delay_time);
81 |
82 |
83 | }
84 |
85 | void checkIfRightIsPressed()
86 | {
87 | if ( digitalRead(right_sw) == LOW )
88 | {
89 | rightPress=true;
90 |
91 | }
92 | }
93 |
94 | void checkIfLeftIsPressed()
95 | {
96 |
97 | if ( digitalRead(left_sw) == LOW )
98 | {
99 | leftPress=true;
100 |
101 | }
102 |
103 | }
104 |
105 |
--------------------------------------------------------------------------------
/BYJ48_STEPPER/BYJ48_STEPPER.ino:
--------------------------------------------------------------------------------
1 | #define IN1 8
2 | #define IN2 9
3 | #define IN3 10
4 | #define IN4 11
5 |
6 | int Steps = 0;
7 | boolean Direction = true;
8 | unsigned long last_time;
9 | unsigned long currentMillis ;
10 | int steps_left=4095;
11 | long time;
12 |
13 | void setup()
14 | {
15 | Serial.begin(115200);
16 | pinMode(IN1, OUTPUT);
17 | pinMode(IN2, OUTPUT);
18 | pinMode(IN3, OUTPUT);
19 | pinMode(IN4, OUTPUT);
20 |
21 |
22 | }
23 | void loop()
24 | {
25 | while(steps_left>0){
26 | currentMillis = micros();
27 | if(currentMillis-last_time>=1000){
28 | stepper(1);
29 | time=time+micros()-last_time;
30 | last_time=micros();
31 | steps_left--;
32 | }
33 | }
34 | Serial.println(time);
35 | Serial.println("Wait...!");
36 | delay(2000);
37 | Direction=!Direction;
38 | steps_left=4095;
39 | }
40 |
41 | void stepper(int xw){
42 | for (int x=0;x7){Steps=0;}
106 | if(Steps<0){Steps=7; }
107 | }
108 |
--------------------------------------------------------------------------------
/NodeMCULEDOnOff/NodeMCULEDOnOff.ino:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | const char* ssid = "Your SSID";
4 | const char* password = "Your password";
5 |
6 | int ledPin = 13;
7 | WiFiServer server(80);
8 |
9 | void setup() {
10 |
11 | pinMode(ledPin,OUTPUT);
12 | digitalWrite(ledPin,LOW);
13 |
14 | Serial.begin(115200);
15 | Serial.println();
16 | Serial.print("Wifi connecting to ");
17 | Serial.println( ssid );
18 |
19 | WiFi.begin(ssid,password);
20 |
21 | Serial.println();
22 | Serial.print("Connecting");
23 |
24 | while( WiFi.status() != WL_CONNECTED ){
25 | delay(500);
26 | Serial.print(".");
27 | }
28 |
29 |
30 | Serial.println();
31 |
32 | Serial.println("Wifi Connected Success!");
33 | Serial.print("NodeMCU IP Address : ");
34 | Serial.println(WiFi.localIP() );
35 |
36 | server.begin();
37 | Serial.println("NodeMCU Server started");
38 |
39 | // Print the IP address
40 | Serial.print("Use this URL to connect: ");
41 | Serial.print("http://");
42 | Serial.print(WiFi.localIP());
43 | Serial.println("/");
44 |
45 | }
46 |
47 | void loop() {
48 |
49 | // Check if a client has connected
50 | WiFiClient client = server.available();
51 | if (!client) {
52 | return;
53 | }
54 |
55 | // Wait until the client sends some data
56 | Serial.println("Hello New client");
57 | while(!client.available()){
58 | delay(1);
59 | }
60 |
61 | // Read the first line of the request
62 | String request = client.readStringUntil('\r');
63 | Serial.println(request);
64 | client.flush();
65 |
66 | // Match the request
67 |
68 | int value = LOW;
69 | if (request.indexOf("/LED=ON") != -1) {
70 | digitalWrite(ledPin, HIGH);
71 | value = HIGH;
72 | }
73 | if (request.indexOf("/LED=OFF") != -1) {
74 | digitalWrite(ledPin, LOW);
75 | value = LOW;
76 | }
77 |
78 | // Set ledPin according to the request
79 | //digitalWrite(ledPin, value);
80 |
81 | // Return the response
82 | client.println("HTTP/1.1 200 OK");
83 | client.println("Content-Type: text/html");
84 | client.println(""); // do not forget this one
85 | client.println("");
86 | client.println("");
87 |
88 | client.print("Led pin is now: ");
89 |
90 | if(value == HIGH) {
91 | client.print("On");
92 | } else {
93 | client.print("Off");
94 | }
95 | client.println("
");
96 | client.println("");
97 | client.println("
");
98 | client.println("");
99 |
100 | delay(1);
101 | Serial.println("Client disonnected");
102 | Serial.println("");
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/code3/code3.ino:
--------------------------------------------------------------------------------
1 | #include "GantryXYZ.h"
2 |
3 | #define right_sw 13
4 | #define left_sw 11
5 |
6 | #define potmeterPin A0
7 |
8 | GantryXYZClasses gantryXYZ;
9 |
10 | volatile boolean rightPress = false;
11 | volatile boolean leftPress = false;
12 |
13 | uint8_t rightBtnState = 0;
14 | uint8_t lastRightBtnState=0;
15 |
16 |
17 | uint8_t leftBtnState = 0;
18 | uint8_t lastLeftBtnState=0;
19 |
20 | unsigned int delay_time=500;
21 |
22 | void setup() {
23 |
24 | pinMode(right_sw, INPUT_PULLUP);
25 | pinMode(left_sw, INPUT_PULLUP);
26 |
27 | Serial.begin(9600); // open coms
28 | gantryXYZ.setFeedrate(1000); // set default speed
29 |
30 | }
31 |
32 | void loop() {
33 |
34 | /*
35 | * Home limit switch Hall Effect sensor normal = 1
36 | * Hit = 0
37 | *
38 | */
39 |
40 | int p = analogRead(potmeterPin);
41 | delay_time = map(p,0,1023,1500,50) ;
42 |
43 | if( !gantryXYZ.is_move){
44 |
45 |
46 |
47 | // Serial.println( delay_time );
48 |
49 | checkIfRightIsPressed();
50 |
51 | checkIfLeftIsPressed();
52 |
53 | if( rightPress){
54 | rightPress = false;
55 | gantryXYZ.prepareMove(-1000,0,0);
56 | }
57 |
58 | else if(leftPress){
59 |
60 | leftPress = false;
61 | gantryXYZ.prepareMove( 450,0,0);
62 | }
63 | }
64 |
65 |
66 | // put your main code here, to run repeatedly:
67 | while(Serial.available() > 0) { // if something is available
68 | char c=Serial.read(); // get it
69 | Serial.print(c); // repeat it back so I know you got the message
70 |
71 | gantryXYZ.storeBuffer( c );
72 |
73 | if(c=='\n') {
74 | // entire message received
75 | gantryXYZ.storeBuffer( c );
76 | Serial.print(F("\r\n")); // echo a return character for humans
77 | gantryXYZ.processCommand(); // do something with the command
78 |
79 | }
80 | }
81 |
82 |
83 | gantryXYZ.move(delay_time);
84 |
85 |
86 | }
87 |
88 | void checkIfRightIsPressed()
89 | {
90 | rightBtnState = digitalRead(right_sw);
91 | if (rightBtnState != lastRightBtnState)
92 | {
93 | if (rightBtnState == 0) {
94 | rightPress=true;
95 | }
96 | delay(50);
97 | }
98 | lastRightBtnState = rightBtnState;
99 | }
100 |
101 | void checkIfLeftIsPressed()
102 | {
103 | leftBtnState = digitalRead(left_sw);
104 |
105 | if (leftBtnState != lastLeftBtnState)
106 | {
107 | if (leftBtnState == 0) {
108 | leftPress=true;
109 | }
110 | delay(50);
111 | }
112 | lastLeftBtnState = leftBtnState;
113 | }
114 |
115 |
--------------------------------------------------------------------------------
/OLEDRangeFinder/OLEDRangeFinder.ino:
--------------------------------------------------------------------------------
1 | /* This example shows how to get single-shot range
2 | measurements from the VL53L0X. The sensor can optionally be
3 | configured with different ranging profiles, as described in
4 | the VL53L0X API user manual, to get better performance for
5 | a certain application. This code is based on the four
6 | "SingleRanging" examples in the VL53L0X API.
7 |
8 | The range readings are in units of mm. */
9 |
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 |
16 | #define OLED_RESET 4
17 | Adafruit_SSD1306 display(OLED_RESET);
18 |
19 | VL53L0X sensor;
20 |
21 | MedianFilter test(10, 0);
22 |
23 | // Uncomment this line to use long range mode. This
24 | // increases the sensitivity of the sensor and extends its
25 | // potential range, but increases the likelihood of getting
26 | // an inaccurate reading because of reflections from objects
27 | // other than the intended target. It works best in dark
28 | // conditions.
29 |
30 | //#define LONG_RANGE
31 |
32 |
33 | // Uncomment ONE of these two lines to get
34 | // - higher speed at the cost of lower accuracy OR
35 | // - higher accuracy at the cost of lower speed
36 |
37 | //#define HIGH_SPEED
38 | //#define HIGH_ACCURACY
39 |
40 | #if (SSD1306_LCDHEIGHT != 64)
41 | #error("Height incorrect, please fix Adafruit_SSD1306.h!");
42 | #endif
43 |
44 | void setup()
45 | {
46 | Serial.begin(9600);
47 | Wire.begin();
48 |
49 | display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
50 |
51 | sensor.init();
52 | sensor.setTimeout(500);
53 |
54 | #if defined LONG_RANGE
55 | // lower the return signal rate limit (default is 0.25 MCPS)
56 | sensor.setSignalRateLimit(0.1);
57 | // increase laser pulse periods (defaults are 14 and 10 PCLKs)
58 | sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
59 | sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
60 | #endif
61 |
62 | #if defined HIGH_SPEED
63 | // reduce timing budget to 20 ms (default is about 33 ms)
64 | sensor.setMeasurementTimingBudget(20000);
65 | #elif defined HIGH_ACCURACY
66 | // increase timing budget to 200 ms
67 | sensor.setMeasurementTimingBudget(200000);
68 | #endif
69 |
70 | // Clear the buffer.
71 | display.clearDisplay();
72 | display.setRotation(2);
73 | display.display();
74 |
75 |
76 | display.setTextColor(WHITE);
77 |
78 |
79 | }
80 | void displayDistance( int val){
81 | display.clearDisplay();
82 | display.setTextSize(4);
83 | display.setCursor(0,0);
84 | display.print(val);
85 |
86 | display.setTextSize(2);
87 | display.setCursor(0,30);
88 | display.print("mm");
89 | display.display();
90 | delay(100);
91 | }
92 | void loop()
93 | {
94 | int o,r = sensor.readRangeSingleMillimeters();
95 | test.in( r );
96 | o = test.out();
97 | Serial.print(o);
98 | if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
99 |
100 | Serial.println();
101 |
102 | displayDistance( o );
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/code2/code2.ino:
--------------------------------------------------------------------------------
1 | #include "GantryXYZ.h"
2 |
3 | #define home_sw 13
4 | #define item1_sw 12
5 | #define item2_sw 11
6 |
7 | GantryXYZClasses gantryXYZ;
8 |
9 | volatile boolean homePress = false;
10 | volatile boolean item1Press = false;
11 | volatile boolean item2Press = false;
12 |
13 | uint8_t homeBtnState = 0;
14 | uint8_t lastHomeBtnState=0;
15 |
16 | uint8_t item1BtnState = 0;
17 | uint8_t lastItem1BtnState=0;
18 |
19 | uint8_t item2BtnState = 0;
20 | uint8_t lastItem2BtnState=0;
21 |
22 | void setup() {
23 |
24 | pinMode(home_sw, INPUT_PULLUP);
25 | pinMode(item1_sw, INPUT_PULLUP);
26 | pinMode(item2_sw, INPUT_PULLUP);
27 |
28 | Serial.begin(9600); // open coms
29 | gantryXYZ.setFeedrate(1000); // set default speed
30 |
31 | }
32 |
33 | void loop() {
34 |
35 | /*
36 | * Home limit switch Hall Effect sensor normal = 1
37 | * Hit = 0
38 | *
39 | */
40 |
41 | if( !gantryXYZ.is_move){
42 |
43 | checkIfHomeIsPressed();
44 | checkIfItem1IsPressed();
45 | checkIfItem2IsPressed();
46 |
47 | if( homePress){
48 | homePress = false;
49 | gantryXYZ.prepareMove(-1000,0,0);
50 | }
51 | else if(item1Press){
52 | item1Press = false;
53 | gantryXYZ.prepareMove( 200,0,0);
54 | }
55 | else if(item2Press){
56 |
57 | item2Press = false;
58 | gantryXYZ.prepareMove( 350,0,0);
59 | }
60 | }
61 |
62 |
63 | // put your main code here, to run repeatedly:
64 | while(Serial.available() > 0) { // if something is available
65 | char c=Serial.read(); // get it
66 | Serial.print(c); // repeat it back so I know you got the message
67 |
68 | gantryXYZ.storeBuffer( c );
69 |
70 | if(c=='\n') {
71 | // entire message received
72 | gantryXYZ.storeBuffer( c );
73 | Serial.print(F("\r\n")); // echo a return character for humans
74 | gantryXYZ.processCommand(); // do something with the command
75 |
76 | }
77 | }
78 |
79 |
80 | gantryXYZ.move();
81 |
82 |
83 | }
84 |
85 | void checkIfHomeIsPressed()
86 | {
87 | homeBtnState = digitalRead(home_sw);
88 | if (homeBtnState != lastHomeBtnState)
89 | {
90 | if (homeBtnState == 0) {
91 | homePress=true;
92 | }
93 | delay(50);
94 | }
95 | lastHomeBtnState = homeBtnState;
96 | }
97 | void checkIfItem1IsPressed()
98 | {
99 | item1BtnState = digitalRead(item1_sw);
100 | if (item1BtnState != lastItem1BtnState)
101 | {
102 | if (item1BtnState == 0) {
103 | item1Press=true;
104 | }
105 | delay(50);
106 | }
107 | lastItem1BtnState = item1BtnState;
108 | }
109 | void checkIfItem2IsPressed()
110 | {
111 | item2BtnState = digitalRead(item2_sw);
112 |
113 | if (item2BtnState != lastItem2BtnState)
114 | {
115 | if (item2BtnState == 0) {
116 | item2Press=true;
117 | }
118 | delay(50);
119 | }
120 | lastItem2BtnState = item2BtnState;
121 | }
122 |
123 |
--------------------------------------------------------------------------------
/code1/GantryClasses.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | GantryClasses.cpp
3 | Author : Jamorn Saksommon
4 | Class
5 | // please see http://www.github.com/MarginallyClever/GcodeCNCDemo for more information.
6 |
7 | Modifly date: 27.01.2017
8 | */
9 | #include
10 | #include "GantryClasses.h"
11 |
12 | GantryClasses::GantryClasses(){
13 |
14 | mode_abs = 1;
15 | feed_rate = 0;
16 | is_move = false;
17 |
18 | }
19 |
20 | void GantryClasses::setFeedrate(float nfr){
21 |
22 |
23 |
24 | nfr = nfr*STEPS_PER_MM/60;
25 | if( ( feed_rate==nfr ) || (nfr>MAX_FEEDRATE || nfr0?HIGH:LOW);
48 |
49 |
50 | }
51 |
52 | delay_t = MAX_FEEDRATE/5000;
53 | accel = 1;
54 | steps_to_accel = delay_t - step_delay;
55 |
56 | if(steps_to_accel > maxsteps/2 )
57 | steps_to_accel = maxsteps/2;
58 |
59 | steps_to_decel = maxsteps - steps_to_accel;
60 |
61 |
62 |
63 | step_count = 0;
64 | prev_time = 0;
65 |
66 | is_move = maxsteps > 0;
67 |
68 | if( is_move){
69 | enableMotor();
70 | }
71 | /*
72 |
73 | Serial.print("START ");
74 | Serial.println(delay_t);
75 | Serial.print("STOP ");
76 | Serial.println(step_delay);
77 |
78 | Serial.print("accel until ");
79 | Serial.println(steps_to_accel);
80 | Serial.print("decel after ");
81 | Serial.println(steps_to_decel);
82 | Serial.print("total ");
83 | Serial.println(maxsteps);
84 |
85 | */
86 |
87 | //r.steps_to_accel = steps_to_accel;
88 | //r.steps_to_decel = steps_to_decel;
89 |
90 |
91 | setPosition(newx,newy,newz);
92 |
93 | }
94 | void GantryClasses::disableMotor(){
95 |
96 | int i;
97 | for(i=0;i= delay_t) ){
122 |
123 | prev_time = curtime;
124 |
125 | for(int j=0;j= maxsteps ) ) {
129 | axis[j].over -= maxsteps;
130 |
131 | _delay = 100;
132 |
133 | digitalWrite(motors[j].step_pin,HIGH);
134 | delayMicroseconds(_delay);
135 | digitalWrite(motors[j].step_pin,LOW);
136 | delayMicroseconds(_delay);
137 | }
138 | }
139 |
140 | if( step_count< steps_to_accel) {
141 | delay_t -= accel;
142 | }
143 | if( step_count>= steps_to_decel) {
144 | delay_t += accel;
145 | }
146 |
147 | step_count++;
148 |
149 | is_move = !(step_count >= maxsteps );
150 |
151 | if( !is_move ){
152 | disableMotor();
153 | }
154 |
155 | }
156 |
157 | }
--------------------------------------------------------------------------------
/code2/GantryClasses.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | GantryClasses.cpp
3 | Author : Jamorn Saksommon
4 | Class
5 | // please see http://www.github.com/MarginallyClever/GcodeCNCDemo for more information.
6 |
7 | Modifly date: 27.01.2017
8 | */
9 | #include
10 | #include "GantryClasses.h"
11 |
12 | GantryClasses::GantryClasses(){
13 |
14 | mode_abs = 1;
15 | feed_rate = 0;
16 | is_move = false;
17 |
18 | }
19 |
20 | void GantryClasses::setFeedrate(float nfr){
21 |
22 |
23 |
24 | nfr = nfr*STEPS_PER_MM/60;
25 | if( ( feed_rate==nfr ) || (nfr>MAX_FEEDRATE || nfr0?HIGH:LOW);
48 |
49 |
50 | }
51 |
52 | delay_t = MAX_FEEDRATE/5000;
53 | accel = 1;
54 | steps_to_accel = delay_t - step_delay;
55 |
56 | if(steps_to_accel > maxsteps/2 )
57 | steps_to_accel = maxsteps/2;
58 |
59 | steps_to_decel = maxsteps - steps_to_accel;
60 |
61 | step_count = 0;
62 | prev_time = 0;
63 |
64 | is_move = maxsteps > 0;
65 |
66 | if( is_move){
67 | enableMotor();
68 | }
69 | /*
70 |
71 | Serial.print("START ");
72 | Serial.println(delay_t);
73 | Serial.print("STOP ");
74 | Serial.println(step_delay);
75 |
76 | Serial.print("accel until ");
77 | Serial.println(steps_to_accel);
78 | Serial.print("decel after ");
79 | Serial.println(steps_to_decel);
80 | Serial.print("total ");
81 | Serial.println(maxsteps);
82 |
83 | */
84 |
85 | //r.steps_to_accel = steps_to_accel;
86 | //r.steps_to_decel = steps_to_decel;
87 |
88 |
89 | setPosition(newx,newy,newz);
90 |
91 | }
92 | void GantryClasses::disableMotor(){
93 |
94 | int i;
95 | for(i=0;i= delay_t) ){
121 |
122 | prev_time = curtime;
123 |
124 | for(int j=0;j= maxsteps ) ) {
128 | axis[j].over -= maxsteps;
129 |
130 | _delay = 100;
131 | /*
132 | Serial.println();
133 | Serial.print( j );
134 | Serial.print(" ");
135 | Serial.print( digitalRead( motors[j].dir_pin ) );
136 | Serial.print(" ");
137 | Serial.print( digitalRead( motors[j].home_switch_pin) );
138 | */
139 | if( ( digitalRead( motors[j].dir_pin) == LOW ) &&
140 | ( digitalRead( motors[j].home_switch_pin) == LOW )){
141 | step_count = maxsteps;
142 | setPosition(0,0,0); // set to zero
143 | }else{
144 |
145 | digitalWrite(motors[j].step_pin,HIGH);
146 | delayMicroseconds(_delay);
147 | digitalWrite(motors[j].step_pin,LOW);
148 | delayMicroseconds(_delay);
149 | }
150 |
151 | }
152 | }
153 |
154 | if( step_count< steps_to_accel) {
155 | delay_t -= accel;
156 | }
157 | if( step_count>= steps_to_decel) {
158 | delay_t += accel;
159 | }
160 |
161 | step_count++;
162 |
163 | is_move = !(step_count >= maxsteps );
164 |
165 | if( !is_move ){
166 | disableMotor();
167 | }
168 |
169 | }
170 |
171 | }
172 |
--------------------------------------------------------------------------------
/code3/GantryClasses.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | GantryClasses.cpp
3 | Author : Jamorn Saksommon
4 | Class
5 | // please see http://www.github.com/MarginallyClever/GcodeCNCDemo for more information.
6 |
7 | Modifly date: 27.01.2017
8 | */
9 | #include
10 | #include "GantryClasses.h"
11 |
12 | GantryClasses::GantryClasses(){
13 |
14 | mode_abs = 1;
15 | feed_rate = 0;
16 | is_move = false;
17 |
18 | }
19 |
20 | void GantryClasses::setFeedrate(float nfr){
21 |
22 |
23 |
24 | nfr = nfr*STEPS_PER_MM/60;
25 | if( ( feed_rate==nfr ) || (nfr>MAX_FEEDRATE || nfr0?HIGH:LOW);
48 |
49 |
50 | }
51 |
52 | delay_t = MAX_FEEDRATE/5000;
53 | accel = 1;
54 | steps_to_accel = delay_t - step_delay;
55 |
56 | if(steps_to_accel > maxsteps/2 )
57 | steps_to_accel = maxsteps/2;
58 |
59 | steps_to_decel = maxsteps - steps_to_accel;
60 |
61 | step_count = 0;
62 | prev_time = 0;
63 |
64 | is_move = maxsteps > 0;
65 |
66 | if( is_move){
67 | enableMotor();
68 | }
69 | /*
70 |
71 | Serial.print("START ");
72 | Serial.println(delay_t);
73 | Serial.print("STOP ");
74 | Serial.println(step_delay);
75 |
76 | Serial.print("accel until ");
77 | Serial.println(steps_to_accel);
78 | Serial.print("decel after ");
79 | Serial.println(steps_to_decel);
80 | Serial.print("total ");
81 | Serial.println(maxsteps);
82 |
83 | */
84 |
85 | //r.steps_to_accel = steps_to_accel;
86 | //r.steps_to_decel = steps_to_decel;
87 |
88 |
89 | setPosition(newx,newy,newz);
90 |
91 | }
92 | void GantryClasses::disableMotor(){
93 |
94 | int i;
95 | for(i=0;i= delay_t) ){
121 |
122 | prev_time = curtime;
123 |
124 | for(int j=0;j= maxsteps ) ) {
128 | axis[j].over -= maxsteps;
129 |
130 | // _delay = 100;
131 | /*
132 | Serial.println();
133 | Serial.print( j );
134 | Serial.print(" ");
135 | Serial.print( digitalRead( motors[j].dir_pin ) );
136 | Serial.print(" ");
137 | Serial.print( digitalRead( motors[j].home_switch_pin) );
138 | */
139 | if( ( digitalRead( motors[j].dir_pin) == LOW ) &&
140 | ( digitalRead( motors[j].home_switch_pin) == LOW )){
141 | step_count = maxsteps;
142 | setPosition(0,0,0); // set to zero
143 | }else{
144 |
145 | digitalWrite(motors[j].step_pin,HIGH);
146 | delayMicroseconds(_delay);
147 | digitalWrite(motors[j].step_pin,LOW);
148 | delayMicroseconds(_delay);
149 | }
150 |
151 | }
152 | }
153 |
154 | if( step_count< steps_to_accel) {
155 | delay_t -= accel;
156 | }
157 | if( step_count>= steps_to_decel) {
158 | delay_t += accel;
159 | }
160 |
161 | step_count++;
162 |
163 | is_move = !(step_count >= maxsteps );
164 |
165 | if( !is_move ){
166 | disableMotor();
167 | }
168 |
169 | }
170 |
171 | }
172 |
--------------------------------------------------------------------------------
/code5/GantryClasses.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | GantryClasses.cpp
3 | Author : Jamorn Saksommon
4 | Class
5 | // please see http://www.github.com/MarginallyClever/GcodeCNCDemo for more information.
6 |
7 | Modifly date: 27.01.2017
8 | */
9 | #include
10 | #include "GantryClasses.h"
11 |
12 | GantryClasses::GantryClasses(){
13 |
14 | mode_abs = 1;
15 | feed_rate = 0;
16 | is_move = false;
17 |
18 | }
19 |
20 | void GantryClasses::setFeedrate(float nfr){
21 |
22 |
23 |
24 | nfr = nfr*STEPS_PER_MM/60;
25 | if( ( feed_rate==nfr ) || (nfr>MAX_FEEDRATE || nfr0?HIGH:LOW);
48 |
49 |
50 | }
51 |
52 | delay_t = MAX_FEEDRATE/5000;
53 | accel = 1;
54 | steps_to_accel = delay_t - step_delay;
55 |
56 | if(steps_to_accel > maxsteps/2 )
57 | steps_to_accel = maxsteps/2;
58 |
59 | steps_to_decel = maxsteps - steps_to_accel;
60 |
61 | step_count = 0;
62 | prev_time = 0;
63 |
64 | is_move = maxsteps > 0;
65 |
66 | if( is_move){
67 | enableMotor();
68 | }
69 | /*
70 |
71 | Serial.print("START ");
72 | Serial.println(delay_t);
73 | Serial.print("STOP ");
74 | Serial.println(step_delay);
75 |
76 | Serial.print("accel until ");
77 | Serial.println(steps_to_accel);
78 | Serial.print("decel after ");
79 | Serial.println(steps_to_decel);
80 | Serial.print("total ");
81 | Serial.println(maxsteps);
82 |
83 | */
84 |
85 | //r.steps_to_accel = steps_to_accel;
86 | //r.steps_to_decel = steps_to_decel;
87 |
88 |
89 | setPosition(newx,newy,newz);
90 |
91 | }
92 | void GantryClasses::disableMotor(){
93 |
94 | int i;
95 | for(i=0;i= delay_t) ){
121 |
122 | prev_time = curtime;
123 |
124 | for(int j=0;j= maxsteps ) ) {
128 | axis[j].over -= maxsteps;
129 |
130 | _delay = 100;
131 | /*
132 | Serial.println();
133 | Serial.print( j );
134 | Serial.print(" ");
135 | Serial.print( digitalRead( motors[j].dir_pin ) );
136 | Serial.print(" ");
137 | Serial.print( digitalRead( motors[j].home_switch_pin) );
138 | */
139 | if( ( digitalRead( motors[j].dir_pin) == LOW ) &&
140 | ( digitalRead( motors[j].home_switch_pin) == LOW )){
141 | step_count = maxsteps;
142 | setPosition(0,0,0); // set to zero
143 | }else{
144 |
145 | digitalWrite(motors[j].step_pin,HIGH);
146 | delayMicroseconds(_delay);
147 | digitalWrite(motors[j].step_pin,LOW);
148 | delayMicroseconds(_delay);
149 | }
150 |
151 | }
152 | }
153 |
154 | if( step_count< steps_to_accel) {
155 | delay_t -= accel;
156 | }
157 | if( step_count>= steps_to_decel) {
158 | delay_t += accel;
159 | }
160 |
161 | step_count++;
162 |
163 | is_move = !(step_count >= maxsteps );
164 |
165 | if( !is_move ){
166 | disableMotor();
167 | }
168 |
169 | }
170 |
171 | }
172 |
--------------------------------------------------------------------------------
/code4/GantryClasses.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | GantryClasses.cpp
3 | Author : Jamorn Saksommon
4 | Class
5 | // please see http://www.github.com/MarginallyClever/GcodeCNCDemo for more information.
6 |
7 | Modifly date: 27.01.2017
8 | */
9 | #include
10 | #include "GantryClasses.h"
11 |
12 | GantryClasses::GantryClasses(){
13 |
14 | mode_abs = 1;
15 | feed_rate = 0;
16 | is_move = false;
17 |
18 | }
19 |
20 | void GantryClasses::setFeedrate(float nfr){
21 |
22 | nfr = nfr*STEPS_PER_MM/60;
23 | if( ( feed_rate==nfr ) || (nfr>MAX_FEEDRATE || nfr0?HIGH:LOW);
46 |
47 |
48 | }
49 |
50 | delay_t = MAX_FEEDRATE/5000;
51 | accel = 1;
52 | steps_to_accel = delay_t - step_delay;
53 |
54 | if(steps_to_accel > maxsteps/2 )
55 | steps_to_accel = maxsteps/2;
56 |
57 | steps_to_decel = maxsteps - steps_to_accel;
58 |
59 | step_count = 0;
60 | prev_time = 0;
61 |
62 | is_move = maxsteps > 0;
63 |
64 | if( is_move){
65 | enableMotor();
66 | }
67 | /*
68 |
69 | Serial.print("START ");
70 | Serial.println(delay_t);
71 | Serial.print("STOP ");
72 | Serial.println(step_delay);
73 |
74 | Serial.print("accel until ");
75 | Serial.println(steps_to_accel);
76 | Serial.print("decel after ");
77 | Serial.println(steps_to_decel);
78 | Serial.print("total ");
79 | Serial.println(maxsteps);
80 |
81 | */
82 |
83 | //r.steps_to_accel = steps_to_accel;
84 | //r.steps_to_decel = steps_to_decel;
85 |
86 |
87 | setPosition(newx,newy,newz);
88 |
89 | }
90 | void GantryClasses::disableMotor(){
91 |
92 | int i;
93 | for(i=0;i= delay_t) ){
119 |
120 | prev_time = curtime;
121 |
122 | for(int j=0;j= maxsteps ) ) {
126 | axis[j].over -= maxsteps;
127 |
128 | // _delay = 100;
129 | /*
130 | Serial.println();
131 | Serial.print( j );
132 | Serial.print(" ");
133 | Serial.print( digitalRead( motors[j].dir_pin ) );
134 | Serial.print(" ");
135 | Serial.print( digitalRead( motors[j].home_switch_pin) );
136 | */
137 | if( ( digitalRead( motors[j].dir_pin) == LOW ) &&
138 | ( digitalRead( motors[j].home_switch_pin) == LOW )){
139 | step_count = maxsteps;
140 | setPosition(0,0,0); // set to zero
141 | }else{
142 |
143 |
144 |
145 | digitalWrite(motors[j].step_pin,HIGH);
146 | delayMicroseconds(_delay);
147 | digitalWrite(motors[j].step_pin,LOW);
148 | delayMicroseconds(_delay);
149 | }
150 |
151 | }
152 | }
153 |
154 | if( step_count< steps_to_accel) {
155 | delay_t -= accel;
156 | }
157 | if( step_count>= steps_to_decel) {
158 | delay_t += accel;
159 | }
160 |
161 | step_count++;
162 |
163 | is_move = !(step_count >= maxsteps );
164 |
165 | if( !is_move ){
166 | disableMotor();
167 | }
168 |
169 | }
170 |
171 | }
172 |
--------------------------------------------------------------------------------