Coder Social home page Coder Social logo

nodelay's People

Contributors

m-tech-creations avatar mats-nk avatar samster395 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nodelay's Issues

NoDelay pass variables

NoDelay pass variables Issue

#include <NoDelay.h>

...

void feeddropPulses(); // Must declare function before noDelay, function can not take arguments

noDelay timedFeeddropPulses(1000 * 10, feeddropPulses); // Creats a noDelay varible set to 10s, will call feeddropPulses function

....

loop

timedFeeddropPulses.update();

....

void feeddropPulses(){
// long dropPulses, int ledGreenfeedLiquid) { // want these passed variables Issue
//}

Thanking You

My code was working but, does not any more.

enabled flag

I use this lib quite a lot - thank you. Once thing that has come up a couple of times now:

I want to disable a timer, AND check elsewhere if ti has been disabled.

Could there be a timerName.enabled() that returns TRUE or FALSE added?

Update method should return false if isenabled == false

We are using nodelay method on very rare occasions to trigger one function after few seconds. But "update" method is still called in each loop although "stop()" was called.

This somehow interfere with mqtt library causing some delays in receiving messages.

What I suggest is to add check at the top of update() method:

bool noDelay::update()
{
	if(!isenabled)
	{
		return false;
	}

Two NoDelay's first delay works but second one fails to delay

First a Great BIG THANK YOU:

issue: Two NoDelay's first delay works but second one fails to delay

Most likely sometime in my code, I am no expert;

Serial message shows function <shakeOffDropOfLiquid()> is called but does not delay

If comment out the first NoDelay calls; this function <shakeOffDropOfLiquid()> does delay; and works by only having one NoDelay call

Code:-

/*
fish_fry_liquid_feeder.ino

Based on : pusher_pan_and_tilt_V2.ino

Turn Glue stick to translation movement of syringe

// I use a Arduino Uno board

A Glue Stick Actuator!
https://www.thingiverse.com/thing:124...
by KikiTay

Arduino Testing 28BYJ-48 Stepper Motor Strength & Power
http://www.dailymotion.com/video/x2jhngo_arduino-testing-28byj-48-stepper-motor-strength-test_tech

Set for 28BYJ-48 stepper

28BYJ-48 stepper with acelstepper library
it is set to accelerate from stating and
deceleration near the stopping. This is to
reduce sudden starts or stops

The AccelStepper library for Arduino
http://www.airspayce.com/mikem/arduino/AccelStepper/index.html

The control board uses the ULN2003 Darlington Array.

This sketch modified from:-

accellsteppertest.ino

Runs one stepper forwards and backwards, accelerating and decelerating
at the limits. Derived from example code by Mike McCauley
Set for 28BYJ-48 stepper

Video: accelstepper 28BYJ-48 demo
http://youtu.be/1F3240hCHE4

An Arduino driven demo of 28BYJ-48 stepper with acelstepper library
showing acceleration and deceleration. The stepper goes one
revolution slowing to a stop before reversing,
with acceleration and deceleration.
The sketch can be obtained from:

Sketch accellsteppertest.ino
accellstepper 28BYJ-48
http://pastebin.com/70QZmCj5

5v 28YBJ-48 Stepper Motor with Gear Reduction,
so it has good torque for its size, but relatively slow motion.
These motors/drivers are made by the millions for A/C units,
fans, duct controls etc. which is why they are so inexpensive.

4 Phase 5 Wire Connection
Phase : 4
Current : 92mA
Resistance : 130 Ω
Voltage : 5V DC
Step Angle (Internal Motor alone): 5.625° (64 steps per revolution)
Step angle: 5.625 x 1/64 at Output Shaft
Gear Reduction ratio: 1 / 64
SO: it should take 4096 steps per output shaft revolution.. To Be Proved.
No-Load Pull-Out Frequency : 800pps
No-Load Pull-In Frequency : 500pps
Pull-In Torque : ≥ 78.4mN.m
Wiring Instruction : A (Blue), B (Pink), C (Yellow), D (Orange), E (Red, Mid-Point)
Weight : 30g
*/

// PWM Vibration Motor Sensor Module Switch For Arduino UNO R3 MEGA2560 Pi eBay https://www.ebay.co.uk/itm/313603434352s liquid off end of syring. Stop double drops, etc

// Based on NoDelay library https://github.com/M-tech-Creations/NoDelay/blob/baad513b9608959136b8c519803c13e470111fd7/examples/BlinkWithNoDelay/BlinkWithNoDelay.ino
// c60d264#diff-751254e83a8e0a9b0ad6ac4a5ce0f5d0c43670a21188642565b266f24f76ac63

// The AccelStepper library for Arduino
// http://www.airspayce.com/mikem/arduino/AccelStepper/index.html

// http://www.airspayce.com/mikem/arduino/AccelStepper/classAccelStepper.html#a748665c3962e66fbc0e9373eb14c69c1

// AccelStepper commands
// http://www.airspayce.com/mikem/arduino/AccelStepper/classAccelStepper.html

// Debugging in Visual Code https://devblogs.microsoft.com/iotdev/debug-your-arduino-code-with-visual-studio-code/

// Timer (DID NOT WORK) https://www.pjrc.com/teensy/td_libs_TimerOne.html
// https://playground.arduino.cc/Code/Timer1/

// interrupts (DID NOT WORK)
// https://arduino.stackexchange.com/questions/30968/how-do-interrupts-work-on-the-arduino-uno-and-similar-boards

#include <AccelStepper.h>

#include "NoDelay.h" // The Magic Code that acutually allows delays for timed movements. https://www.arduino.cc/reference/en/libraries/nodelay/

// ACTUAL USE 4 hours: long millisecondsBetweenDrops= 14400000; // (14400000) 14,400,000 milliseconds 4 Hours between drops
long millisecondsBetweenDrops = 15000; // TESTING (15000) milliseconds 15 seconds between drops

long vibrationMotorDelay = 2000; // 2000 milliseconds 2 seconds; Convert milliseconds to hours https://converter.net/time/14400000-milliseconds-to-hours

// noDelay Must declare function before noDelay, function can not take arguments
void FeedDropPulses();
void shakeOffDropOfLiquid();
void unFeedDropPulses();

noDelay nFeedDropPulses(millisecondsBetweenDrops); // Creates a noDelay variable. Uses the NoDelay library; Convert milliseconds to hours https://converter.net/time/14400000-milliseconds-to-hours

noDelay nVibrationMotorDelay(vibrationMotorDelay); // Creates a noDelay variable. Uses the NoDelay library; Convert milliseconds to hours https://converter.net/time/14400000-milliseconds-to-hours

#define FULLSTEP 4
#define HALFSTEP 8

// Positive Clockwise looking towards the shaft
// Negative Anticlockwise looking towards the shaft
// There appears to be a limit on this value
// I have only tried it upto 5 and -5

// Declare variables for the stepper motor pins

int motorPin1 = 8; // Blue - 28BYJ48 pin 1 Arduino Uno White Pin 8
int motorPin2 = 9; // Pink - 28BYJ48 pin 2 Arduino Uno Grey Pin 9
int motorPin3 = 10; // Yellow - 28BYJ48 pin 3 Arduino Uno Purple Pin 10
int motorPin4 = 11; // Orange - 28BYJ48 pin 4 Arduino Uno Blue Pin 11
// Red - 28BYJ48 pin 5 (VCC)

#define vibrationMotorPin 7

// The Stepper Feeder Motor sequence 1, 3, 2, 4 required for proper sequencing of 28BYJ48
AccelStepper stepper2(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);

// Control buttons Feed and Unfeed
int buttonGreenPinFeedLiquid = A2;
int buttonYellowPinUnfeedLiquid = A3;

// LED's Signal Feed and Unfeed
int ledGreenFeedLiquid = A4;
int ledYellowUnfeedLiquid = A5;

// The Motor Two buttons Feed or Unfeed if a button is pressed
// High = Off not pressed
boolean buttonGreenPinFeedVal = LOW;
boolean buttonYellowPinUnfeedVal = LOW;

// Feeding starting postion
long pusherFeedPosition = 0;

long oneTurnPulses = 4100; // lower value turn stepper quicker //256; //1024; // 2048; //4100; 2038;

long fourTurnPulses = oneTurnPulses * 4;
//long halfdropPulses = int(oneTurnPulses / 2);
//long quarterTurnPulses = int(oneTurnPulses / 4);

long oneDropPulses = 123; // TESTING !!! pulses for one drop.. Baby fry liquid once ever 4 hours. For My JR 10Ml Inkjet Refill Syringe, that is only filled to 4 ml should last 30 Days

// Feed and unfeed
const int maximumPusherFeedPositionDrops = 120 * oneDropPulses; // Maximun drops about 4ml
const int maximumPusherUnFeedPositionDrops = 0;

//////////////////////////////////////////////
//////////////////////////////////////////////

void setup()
{
Serial.begin(9600); // Standard is 9600 Serial Monitor display

// Set up LED Feed Unfeed
pinMode(ledGreenFeedLiquid, OUTPUT);
pinMode(ledYellowUnfeedLiquid, OUTPUT);

// Buttons set to input
pinMode(buttonGreenPinFeedLiquid, INPUT);
pinMode(buttonYellowPinUnfeedLiquid, INPUT);

pinMode(vibrationMotorPin, OUTPUT); // define a pin as output

// Buttons turn on internal pull-up resistor.
digitalWrite(buttonGreenPinFeedLiquid, HIGH);
digitalWrite(buttonYellowPinUnfeedLiquid, HIGH);

// Stepper Maximun Speed
// The desired maximum speed in steps per second.
// Must be > 0. Caution: Speeds that exceed the
// maximum speed supported by the processor
// may Result in non-linear accelerations and decelerations.
stepper2.setMaxSpeed(1000.0);

// Stepper Acceleration
// Higher value=shorter
// The desired acceleration in steps per second per second.
// Must be > 0.0. This is an expensive call since it
// requires a square root to be calculated.
// Dont call more often than needed
// 100 = No acceleration
// Note Any deacceleration will cause a run on after while
// the deacceleration takes place
stepper2.setAcceleration(50.0);

// Stepper Speed
// The desired constant speed in steps per second.
// Positive is clockwise. Speeds of more than
// 1000 steps per second are unreliable.
// Very slow speeds may be set
// (eg 0.00027777 for once per hour, approximately.
// Speed accuracy depends on the Arduino crystal.
// Jitter depends on how frequently you call the
// RunSpeed() function.
stepper2.setSpeed(700); // RPM; remember 1 to 64 gear so 64 time slower = more torque!!!

resetStepper(); // Clear any old positions

// Start up for Stepper
stepper2.enableOutputs();
}

/////////////////////////////////////////
/////////////////////////////////////////

void loop()
{
// Start witha stop to clear any old positions, etc..
stepper2.stop();

// Turn Signal LED's off
digitalWrite(ledGreenFeedLiquid, LOW);
digitalWrite(ledYellowUnfeedLiquid, LOW);

buttonGreenPinFeedVal = digitalRead(buttonGreenPinFeedLiquid);
buttonYellowPinUnfeedVal = digitalRead(buttonYellowPinUnfeedLiquid);

// Feed after Time set: Checks to see if set time has past and no buttons pressed
if (nFeedDropPulses.update() && (pusherFeedPosition < maximumPusherFeedPositionDrops) // Uses the NoDelay library
&& ((buttonGreenPinFeedVal == HIGH && buttonYellowPinUnfeedVal == HIGH))) {
FeedDropPulses(oneDropPulses, ledGreenFeedLiquid);

// Remove any liquid hangging, due to liquid tension etc, from end of syring. Stop build up of liquid causing double drops, etc.
shakeOffDropOfLiquid();  // Uses the NoDelay library

}

// Feeding button pressed /////////////////////////////////////////////////////////////
if ((buttonGreenPinFeedVal == LOW) && (pusherFeedPosition >= maximumPusherUnFeedPositionDrops)) {
FeedDropPulses(oneDropPulses, ledGreenFeedLiquid);

// Remove any liquid hangging, due to liquid tension etc, from end of syring. Stop build up of liquid causing double drops, etc.
shakeOffDropOfLiquid();  // Uses the NoDelay library

}

// Unfeeding button pressed ////////////////////////////////////////////////////////////
if (buttonYellowPinUnfeedVal == LOW && (pusherFeedPosition < maximumPusherFeedPositionDrops)) {
unFeedDropPulses(oneDropPulses, ledYellowUnfeedLiquid); // Uses the NoDelay library
}

// Limit LED signals ////////////////////////////////////////////////////////////

if (pusherFeedPosition >= maximumPusherFeedPositionDrops) {
flashLED(ledGreenFeedLiquid);
}

if (pusherFeedPosition <= maximumPusherUnFeedPositionDrops) {
flashLED(ledYellowUnfeedLiquid);
}

// reset punger position at start //////////////////////////////////////////////////////////////
// Paused feed limit automattically return plunger to start and no buttons pressed, using manual
if ((pusherFeedPosition >= maximumPusherFeedPositionDrops)
&& (buttonGreenPinFeedVal == HIGH && buttonYellowPinUnfeedVal == HIGH)) {

unFeedDropPulses(maximumPusherFeedPositionDrops, ledYellowUnfeedLiquid); // Uses the NoDelay library

// Allow stepper to be manually moved by Hand
resetStepper();

while (1) {}; // Stop the Program actions, (loop forever), until plugged in again, allow filling of syringe, etc...

}
}

/////////////////////////////////////////
/////////////////////////////////////////

void FeedDropPulses(long dropPulses, int ledGreenfeedLiquid) {
long positionNow = stepper2.currentPosition();

digitalWrite(ledGreenfeedLiquid, HIGH);

pusherFeedPosition = pusherFeedPosition + oneDropPulses; // Correct direction to feed pusher

// ADDING Serial slows down movement, turning, "a lot", time taken to display

// Serial.println("feed");
// Serial.print("pusherFeedPosition=");
// Serial.print(pusherFeedPosition);
// Serial.print(" dropPulses=");
// Serial.print(dropPulses);
// Serial.print(" maximumPusherFeedPositionDrops=");
// Serial.print(maximumPusherFeedPositionDrops);
// Serial.println();
// Serial.println("
**************************");

// Moves the motor (with acceleration/deceleration) to the new target position and blocks until it is at position. Don't use this in event loops, since it blocks
stepper2.runToNewPosition(positionNow - dropPulses);

// delay(60000); // Time to allow stepper to move

// Turn Signal LED off
digitalWrite(ledGreenFeedLiquid, LOW);
}

/////////////////////////////////////////
/////////////////////////////////////////

void unFeedDropPulses(long dropPulses, int ledYellowUnfeedLiquid) { // Uses the NoDelay library
long positionNow = stepper2.currentPosition();

digitalWrite(ledYellowUnfeedLiquid, HIGH);

pusherFeedPosition = pusherFeedPosition - oneDropPulses; // Correct direction to unfeed pusher

// Serial.println("unFeed");
// Serial.print("pusherFeedPosition=");
// Serial.print(pusherFeedPosition);
// Serial.print(" dropPulses=");
// Serial.print(dropPulses);
// Serial.print(" maximumPusherFeedPositionDrops=");
// Serial.print(maximumPusherFeedPositionDrops);
// Serial.println();
// Serial.println("
***************************");

// Moves the motor (with acceleration/deceleration) to the new target position and blocks until it is at position. Don't use this in event loops, since it blocks.
stepper2.runToNewPosition(positionNow + dropPulses);

// delay(60000); // Time to allow stepper to move

// Turn Signal LED off
digitalWrite(ledYellowUnfeedLiquid, LOW);
}

/////////////////////////////////////////
/////////////////////////////////////////

void shakeOffDropOfLiquid() {
// Runs Phone Vibration Motor to remove any liquid hanging, due to liquid tension etc, from end of syring. Stop build up of liquid causing double drops, etc.

Serial.println("**shakeOffDropOfLiquid START");

digitalWrite(vibrationMotorPin, HIGH); // Turn Phone Vibration Motor on for a short time

if (nVibrationMotorDelay.update()) {
Serial.println("shakeOffDropOfLiquid STOP inside");
Serial.println("
***************************");

digitalWrite(vibrationMotorPin, LOW); // Turn Phone Vibration Motor off

}
}

/////////////////////////////////////////
/////////////////////////

void resetStepper() {

stepper2.setCurrentPosition(0);

// Allow stepper to be manually moved by Hand
stepper2.disableOutputs();

stepper2.stop();
}

////////////////////////////////////////
/////////////////////////////////////////

void flashLED(int led) {

digitalWrite(led, HIGH);

delay(250);

digitalWrite(led, LOW);

delay(250);

digitalWrite(led, HIGH);

delay(250);

digitalWrite(led, HIGH);

delay(250);

// finish with LED turned off
digitalWrite(led, LOW);

delay(250);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.