Skip to content

Commit

Permalink
Added rotary encoder; stepper now with no delay
Browse files Browse the repository at this point in the history
  • Loading branch information
gniezen committed Sep 2, 2014
1 parent 61fe670 commit 70c3fd6
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions ui/ui.ino
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
#include <EEPROM.h>
#include <SPI.h>
#include <GD2.h>
#include <Encoder.h>

//#include "spinner_assets.h"
#include "default_assets.h"

int dirpin = 30;
int steppin = 32;

// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
Encoder knobLeft(18, 19);
Encoder knobRight(20, 21);

int i = 0;
int pressed = 0;
int pressed = 0;
long positionLeft = -999;
long positionRight = -999;
char buff[24];

long timeBetweenSteps = 1000; // in ms
long previousMillis = 0;

void setup()
{
Expand All @@ -24,22 +37,43 @@ void setup()

void loop()
{
Serial.begin(9600);

long newLeft, newRight;
newLeft = knobLeft.read();
newRight = knobRight.read();
if (newLeft != positionLeft || newRight != positionRight) {

sprintf(buff, "%ld,%ld,", newLeft/2, newRight/2);
Serial.println(buff);
positionLeft = newLeft;
positionRight = newRight;
}

//Drive stepper motor

digitalWrite(dirpin, HIGH); // Set the direction.
delay(1000); //time between steps in ms

for (int i = 0; i<10; i++) // number of microsteps at one time
{
digitalWrite(steppin, LOW);
digitalWrite(steppin, HIGH); // Creates 'rising edge'
delayMicroseconds(5000); //motor speed
unsigned long currentMillis = millis();

if(currentMillis - previousMillis > timeBetweenSteps) {
// save the last time you blinked the LED
previousMillis = currentMillis;

for (int i = 0; i<10; i++) // number of microsteps at one time
{
digitalWrite(steppin, LOW);
digitalWrite(steppin, HIGH); // Creates 'rising edge'
delayMicroseconds(5000); //motor speed
}
}

// Graphics

//GD.ClearColorRGB(0x103000);
GD.get_inputs();
GD.Clear();
GD.cmd_text(240, 68, 31, OPT_CENTER, "56.7 mL/h");
GD.cmd_text(240, 68, 31, OPT_CENTER, buff);

/*
GD.Begin(POINTS); // draw 50-pixel wide green circles
Expand Down

0 comments on commit 70c3fd6

Please sign in to comment.