i dont seem to be able to get delayMicroseconds to work from the arduino iot cloud, delay works if substituted but i need microseconds to control the stepper delays(not using a library).
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/862e6649-0da1-4814-82e7-3a8560ff4f19
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudLight led;
bool step_back;
bool step_for;
CloudTime step_speed;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
int xstep = 10;
int xenable = 9;
int xdir = 8;
unsigned int speedState;
#include "thingProperties.h"
void setup() {
pinMode(xstep, OUTPUT);
pinMode(xenable, OUTPUT);
pinMode(xdir, OUTPUT);
pinMode(13, OUTPUT);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
digitalWrite(xenable, HIGH);
speedState = step_speed;
if(step_for == HIGH){
onStepForChange();
}
if(step_back == HIGH){
onStepBackChange();
}
}
/*
Since Led is READ_WRITE variable, onLedChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLedChange() {
if(led == HIGH){
digitalWrite(13, HIGH);
}
else{
digitalWrite(13, LOW);
// Add your code here to act upon Led change
}
}
/*
Since StepFor is READ_WRITE variable, onStepForChange() is
executed every time a new value is received from IoT Cloud.
*/
void onStepForChange() {
digitalWrite(xenable, LOW);
digitalWrite(xdir, HIGH);
digitalWrite(xstep, HIGH);
delayMicroseconds(speedState);
//delay(speedState);
digitalWrite(xstep, LOW);
delayMicroseconds(speedState);
//delay(speedState);
// Add your code here to act upon StepFor change
}
/*
Since StepBack is READ_WRITE variable, onStepBackChange() is
executed every time a new value is received from IoT Cloud.
*/
void onStepBackChange() {
digitalWrite(xenable, LOW);
digitalWrite(xdir, LOW);
digitalWrite(xstep, HIGH);
delayMicroseconds(speedState);
//delay(speedState);
digitalWrite(xstep, LOW);
delayMicroseconds(speedState);
//delay(speedState);
// Add your code here to act upon StepBack change
}
/*
Since StepSpeed is READ_WRITE variable, onStepSpeedChange() is
executed every time a new value is received from IoT Cloud.
*/
void onStepSpeedChange() {
// Add your code here to act upon StepSpeed change
}
if i change delayMicroseconds to delay everything works albeit very slowly.
any help gratefully recieved
rich