-
Notifications
You must be signed in to change notification settings - Fork 0
/
stepper_motor.ino
119 lines (85 loc) · 2.87 KB
/
stepper_motor.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// AccelStepper - Version: Latest
#include <AccelStepper.h>
#include <MultiStepper.h>
#include <ESP8266Wifi.h>
#include <Arduino.h>
#include <ESP8266WifiMulti.h>
#include <ESP8266HTTPClient.h>
#include <WifiClient.h>
//const int stepsPerRev = 200; //change to fit the number of steps per revolution for motor
ESP8266WifiMulti WifiMulti;
#define HALFSTEP 8
const int limitPin = 7;
int limitState = 0;
#define motorPin1 8
#define motorPin2 9
#define motorPin3 10
#define motorPin4 11
//initializes the stepper motor library on pins 8 through 11
AccelStepper testStep(HALFSTEP, motorPin1, motorPin2, motorPin3, motorPin4);
int revCheck = 0; //0 for no revolution done, 1 for a revolution made
int revolution = 4096/2; // revolution measure
int userTime;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println();
Serial.println();
Serial.println();
for (uint8_t t = 4; t > 0; t--) {
Serial.printf("[SETUP] Wait %d...\n", t);
Serial.flush();
delay(1000);
}
Wifi.mode(WIFI_STA);
WifiMulti.addAP("Noriega5-5G", "Alexandria288");
pinMode(limitPin, INPUT);
testStep.setMaxSpeed(10000.0);
testStep.setAcceleration(1000.0);
testStep.setSpeed(50);
testStep.moveTo(revolution/4); // 1/8 of a full revolution
}
void loop() {
userTime = digitalRead(limitState);
Serial.print(userTime);
Serial.println();
String myString = "https://edd-medicine-dispenser-1-epicslayer18.c9users.io/medication-dispenser/selectMedication.php";
String finalString = myString + userTime;
Serial.print(finalString);
if ((WiFiMulti.run() == WL_CONNECTED)) {
Serial.print(userTime);
WiFiClient client;
HTTPClient http;
Serial.print("[HTTP] begin...\n");
if (http.begin(client, finalString)) { // HTTP
Serial.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
Serial.println(payload);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
} else {
Serial.printf("[HTTP} Unable to connect\n");
}
}
delay(1000);
testStep.run();
/*
int sensorReading = analogRead(A0);
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
if(motorSpeed > 0) {
testStep.setSpeed(motorSpeed);
testStep.step(stepsPerRev / 100);
}
*/
}