diff --git a/Rotabator.ino b/Rotabator.ino index 81a7996..b9f058d 100644 --- a/Rotabator.ino +++ b/Rotabator.ino @@ -1,66 +1,49 @@ -#include -#include -#include -#include -#include -char ssid[] = "cohabit"; // your network SSID (name) -char pass[] = "lewifidecohabit"; // your network password +const int stepPin = 14; -// A UDP instance to let us send and receive packets over UDP -WiFiUDP Udp; -const unsigned int localPort = 16403; // local port to listen for UDP packets (here's where we send the packets) -int stepPin = 14; -int dirPin = 12; +const int dirPin = 12; -void setup() -{ -Serial.begin(115200); -// initialize LED digital pin as an output. -pinMode(stepPin, OUTPUT); -pinMode(dirPin, OUTPUT); -Serial.println(); -Serial.print("Connecting to "); -Serial.println(ssid); -WiFi.begin(ssid, pass); +int customDelay,customDelayMapped; // Defines variables -while (WiFi.status() != WL_CONNECTED) { -delay(500); -Serial.print("."); -} -Serial.println(""); +void setup() { -Serial.println("WiFi connected"); -Serial.println("IP address: "); -Serial.println(WiFi.localIP()); + // Sets the two pins as Outputs + + Serial.begin(115200); + + pinMode(stepPin,OUTPUT); + + pinMode(dirPin,OUTPUT); + + digitalWrite(dirPin,HIGH); //Enables the motor to move in a particular direction -Serial.println("Starting UDP"); -Udp.begin(localPort); -Serial.print("Local port: "); -Serial.println(localPort); -digitalWrite(dirPin, HIGH); } -void step(OSCMessage &msg) { -switch (msg.getInt(0)) { -case 0: -digitalWrite(stepPin, LOW); -break; -case 1: -digitalWrite(stepPin, HIGH); -break; -} +void loop() { + + + + customDelayMapped = speedUp(); // Gets custom delay values from the custom speedUp function + // Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends + + digitalWrite(stepPin, HIGH); + + delayMicroseconds(customDelayMapped); + + digitalWrite(stepPin, LOW); + + delayMicroseconds(customDelayMapped); + + Serial.println(customDelayMapped); + } -void loop() -{ -OSCMessage msg; -int size = Udp.parsePacket(); +// Function for reading the Potentiometer + +int speedUp() { + + int customDelay = analogRead(6); // Reads the potentiometer + int newCustom = map(customDelay, 0, 8191, 300,3000); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000) + + return newCustom; -if (size > 0) { -while (size--) { -msg.fill(Udp.read()); -} -//step(msg); -step(msg); -} } \ No newline at end of file