Comments and Cleanup

This commit is contained in:
mrcory
2019-05-22 18:44:41 -04:00
parent 4a8119086a
commit 52667c8bc8
2 changed files with 46 additions and 31 deletions
+25 -6
View File
@@ -20,16 +20,23 @@ int connectTimeout = 100; // How many attempts can we make before giving up on B
//------Timer
int stepperPos[] = {0,6000};
int stepperTime[2][2] = {};
//------Not currently used
/*Set size for the eeprom.
* 512 is way more than will be needed.
* All that is being stored there is position data
* after each move is completed.
*/
const int eepromSize = 512;
const int stepPerRev = 4096;
//Declare motor pins
#define mtrPin1 D8//D5
#define mtrPin2 D6//D7
#define mtrPin3 D7//D6
#define mtrPin4 D5//D8
const int stepPerRev = 4096; //Steps needed to make 1 revolution
//Button Config
#define buttonEnable true //True to enable button controls
#define buttonPin A0 //Analog pin for buttons
@@ -39,22 +46,34 @@ const int stepPerRev = 4096;
#define dnVal 875
#define rsVal 1024
/* The margin that analogButtons uses to determine
* if a button has been pressed. Default is 20, but
* I use 30. As long as there is plenty of gap between
* values set above, this can be set larger.
*/
#define buttonMargin 30
#define ANALOGBUTTONS_SAMPLING_INTERVAL 10
//Feedback for button presses
#define lightEnable true //Allow control of LED
#define lightMode 1 //0-PWM 1-FastLED
#define ledPin D4 //Feedback LED
/* This will allow control of an accessory light via
* PWM or FastLED.
* If using FastLED controlled lights, be careful of
* the number you use. Always calcualte the max possible
* power consumption and add a safety margin.
*/
#define alternateFunction false //Enable alternate use of the reset button
#define lightMode 1 //0-PWM 1-FastLED | PWM is currently not implemented.
int ledBrightness = 2;
//Light accessory settings (Not the feedback LED)
//Using FastLED to run some WS2812
int ledBrightness = 2; //Starting brightness
int ledButtonBrightness = 50; //Brightness to use when using rst button to turn on light.
//Extra Stuff
#define rtcBlynk false
#define cmds true //After setting up positions, cmdArduino can be disabled
+21 -25
View File
@@ -16,15 +16,14 @@
#include <AccelStepper.h>
#include <EEPROM.h>
#define HALFSTEP 8
#define HALFSTEP 8 //This is for AccelStepper
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Ethernet.h>
#include "config.h"
//FastLED Setup
#include <FastLED.h>
FASTLED_USING_NAMESPACE
#define NUM_LEDS 9
@@ -35,13 +34,12 @@ FASTLED_USING_NAMESPACE
CRGB leds[NUM_LEDS];
#if cmds
#if cmds //Enable cmdArduino
#include <Cmd.h>
#endif
byte lastPosition = 2;
byte lastPosition = 2; //Storing a starting value
//Configure AccelStepper
AccelStepper stepper(HALFSTEP, mtrPin1,mtrPin2,mtrPin3,mtrPin4);
@@ -71,10 +69,11 @@ int oldBrightness = ledBrightness;
#include "functions.h"
#if buttonEnable
#if buttonEnable //Enable physical buttons
#include <AnalogButtons.h>
//Here we are setting up the fuctions that will be called via the physical buttons.
void upClick() {
Serial.println("Up Click");
if (lastPosition > 1) {
@@ -126,14 +125,15 @@ int oldBrightness = ledBrightness;
ledTurn(1);
}
AnalogButtons buttons(buttonPin, INPUT,4,30);
//Create tha actual buttons
AnalogButtons buttons(buttonPin, INPUT,4,buttonMargin);
Button up = Button(upVal, &upClick, &upHold, 1000, 5000);
Button down = Button(dnVal, &downClick, &downHold, 1000, 5000);
Button rst = Button(rsVal, &resetClick, &resetHold, 2500, 5000);
#endif
#if rtcBlynk
#if rtcBlynk //Enable the RTC feature from Blynk
//Blynk RTC
#include <WidgetRTC.h>
WidgetRTC RTC;
@@ -143,8 +143,6 @@ int oldBrightness = ledBrightness;
void setup() {
//FastLED.addLeds<WS2811, 2, GRB>(leds, NUM_LEDS);
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
pinMode(ledPin,OUTPUT);
@@ -156,7 +154,7 @@ void setup() {
buttons.add(rst);
#endif
#if cmds
#if cmds //Define our serial commands if enabled
cmdInit(&Serial);
cmdAdd("move",manualMove);
cmdAdd("rst",homePos);
@@ -171,9 +169,9 @@ void setup() {
delay(50);
blynkConfig();
EEPROM.begin(eepromSize);
EEPROM.begin(eepromSize); //Initialize the EEPROM with our selected size
if (EEPROM.read(0) == 1) {
if (EEPROM.read(0) == 1) { //If flagged in EEPROM; we load our current position
configLoad();
}
@@ -197,7 +195,7 @@ void setup() {
FastLED.setBrightness(ledBrightness);
}
} //END SETUP
void loop() {
@@ -226,21 +224,19 @@ void loop() {
setHome = false;
}
lightControl();
if (ledBrightness != oldBrightness) {
FastLED.setBrightness(ledBrightness);
FastLED.show();
}
lightControl();
if (ledBrightness != oldBrightness) {
FastLED.setBrightness(ledBrightness);
FastLED.show();
}
}
stepper.run(); //AccelStepper runs here
moveNow();
}
} //END LOOP