code pot stepper
This commit is contained in:
parent
f99cb0c0bb
commit
addd364b61
|
@ -1,66 +1,49 @@
|
|||
#include <WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include <OSCMessage.h>
|
||||
#include <OSCBundle.h>
|
||||
#include <OSCData.h>
|
||||
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;
|
||||
|
||||
int customDelay,customDelayMapped; // Defines variables
|
||||
|
||||
void setup() {
|
||||
|
||||
// Sets the two pins as Outputs
|
||||
|
||||
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);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println("");
|
||||
digitalWrite(dirPin,HIGH); //Enables the motor to move in a particular direction
|
||||
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
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:
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue