WOOT! I found the error after reading all lines of code that I had modified...
So now I'm back to square one: my code worked and yours didn't on the board, but I'll make a diagram to show my wiring exactly how I have it.
Here's my code:
#include <Keypad.h>
#include <Adafruit_NeoPixel.h>
// Define the states for the lock state machine
#define LOCKED 2
#define UNLOCKED 0
// State Variables: Initialize to the locked state
int LockState = LOCKED;
long StartTime = 0;
int position = 0;
int Distance = 0; //Record steps
// Define your password key sequence here
char* secretCode = "2301000";
// Keypad key matrix:
const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] =
{
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
// Keypad pin definitions
byte rowPins[rows] = {5, 6, 7, 8};
byte colPins[cols] = {2, 3, 4};
// Instantiate the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
int transistorPin = 9; //LED Transistor Pin Definition
int StepperDistance = 10; //Stepper Distance Pin Definiton
int StepperDirection = 11; //Stepper Direction Pin Definition
int StepperStart = 12; //Stepper Engage Pin Definition
int ColorLED = 13; //Color LED Definition
Adafruit_NeoPixel IndicatorLED = Adafruit_NeoPixel(2, ColorLED, NEO_RGB + NEO_KHZ800);
//400 IS FOR WS2811 and 800 IS FOR WS2812
void setup()
{
//Set stepper and Light Parts as Outputs)
pinMode(transistorPin, OUTPUT);
pinMode(StepperDistance, OUTPUT);
pinMode(StepperDirection, OUTPUT);
pinMode(StepperStart, OUTPUT);
//Set stepper settings off and Clockwise
digitalWrite(StepperStart, LOW);
digitalWrite(StepperDistance, LOW);
digitalWrite(StepperDirection, LOW);
// Initialize state of lock and communications.
setLockState(LOCKED);
IndicatorLED.begin();
IndicatorLED.show(); //Initialize LEDs to 'off'
Serial.begin(9600);
}
void loop()
{
// Run the state machine:
// Locked State - Monitor keypad for valid Password code entry
if (LockState == LOCKED)
{
char key = keypad.getKey();
if (key == '*' || key == '#')
{
position = 0;
}
if (key != 0)
{
if (key == secretCode[position]) // Valid key in Password sequence
{
Serial.print("Matched ");
Serial.print(key);
Serial.print("-at-");
Serial.println(position);
position ++;
IndicatorLED.setPixelColor(0, 255, 0, 0);
IndicatorLED.setPixelColor(1, 255, 0, 0);
IndicatorLED.show();
delay(10);
IndicatorLED.setPixelColor(0, 0, 0, 0);
IndicatorLED.setPixelColor(1, 0, 0, 0);
IndicatorLED.show();
//Green LED flash
}
else // Invalid key - start all over again
{
Serial.println("Invalid Code!");
position = 0;
IndicatorLED.setPixelColor(0, 0, 255, 0);
IndicatorLED.setPixelColor(1, 0, 255, 0);
IndicatorLED.show();
delay(100);
IndicatorLED.setPixelColor(0, 0, 0, 0);
IndicatorLED.setPixelColor(1, 0, 0, 0);
IndicatorLED.show();
//Red LED on for 2 seconds
}
}
if (position == 7) // Password successfully entered - advance state
{
setLockState(UNLOCKED);
position = 0;
}
delay(100);
}
}
// Set the state and the time of the state change
void setLockState(int state)
{
LockState = state;
StartTime = millis ();
if (state == LOCKED)
{
Serial.println("Locked!");
}
else if (state == UNLOCKED)
{
Serial.println("Unlocked!");
//MyStepper.step(STEPS);
digitalWrite(StepperStart, HIGH);
delay(25);
digitalWrite(StepperDirection, LOW);
digitalWrite(StepperDistance, HIGH);
delay(100);
digitalWrite(StepperDistance, LOW);
digitalWrite(StepperStart, LOW);
//Code for 90 degree clockwise turn below... 1:1 stepping ratio, no chopping
if(Distance < 90);
{
digitalWrite(StepperDirection, LOW);
digitalWrite(StepperDistance, HIGH);
delayMicroseconds(100);
digitalWrite(StepperDistance, LOW);
delayMicroseconds(100);
Distance = Distance + 1; //Record this Step
Serial.println("Stepped!");
}
for (int brightness = 0; brightness < 255; brightness++) {
analogWrite(transistorPin, brightness);
delay(12);
}
rainbow(12); //Start flashing Rainbow LEDs
IndicatorLED.setPixelColor(0, 0, 0, 0);
IndicatorLED.setPixelColor(1, 0, 0, 0); //0, Begin Rainbow Countdown to Close ROYGBP
IndicatorLED.show();
delay(1000);
IndicatorLED.setPixelColor(0, 0, 255, 0);
IndicatorLED.setPixelColor(1, 0, 255, 0); //RED
IndicatorLED.show();
delay(1000);
IndicatorLED.setPixelColor(0, 0, 0, 0);
IndicatorLED.setPixelColor(1, 0, 0, 0);
IndicatorLED.show();
delay(100);
IndicatorLED.setPixelColor(0, 100, 255, 0);
IndicatorLED.setPixelColor(1, 100, 255, 0); //ORANGE
IndicatorLED.show();
delay(1000);
IndicatorLED.setPixelColor(0, 0, 0, 0);
IndicatorLED.setPixelColor(1, 0, 0, 0);
IndicatorLED.show();
delay(100);
IndicatorLED.setPixelColor(0, 255, 255, 0);
IndicatorLED.setPixelColor(1, 255, 255, 0); //YELLOW
IndicatorLED.show();
delay(1000);
IndicatorLED.setPixelColor(0, 0, 0, 0);
IndicatorLED.setPixelColor(1, 0, 0, 0);
IndicatorLED.show();
delay(100);
IndicatorLED.setPixelColor(0, 255, 0, 0);
IndicatorLED.setPixelColor(1, 255, 0, 0); //GREEN
IndicatorLED.show();
delay(1000);
IndicatorLED.setPixelColor(0, 0, 0, 0);
IndicatorLED.setPixelColor(1, 0, 0, 0);
IndicatorLED.show();
delay(100);
IndicatorLED.setPixelColor(0, 0, 0, 255);
IndicatorLED.setPixelColor(1, 0, 0, 255); //BLUE
IndicatorLED.show();
delay(1000);
IndicatorLED.setPixelColor(0, 0, 0, 0);
IndicatorLED.setPixelColor(1, 0, 0, 0);
IndicatorLED.show();
delay(100);
IndicatorLED.setPixelColor(0, 0, 255, 255);
IndicatorLED.setPixelColor(1, 0, 255, 255); //PURPLE
IndicatorLED.show();
//Fade off the Light
for (int brightness = 255; brightness >= 0; brightness--) {
analogWrite(transistorPin, brightness);
delay(20);
}
//Close Cabinet
//Code for 90 degree clockwise turn below...
//Indicate the code will return to locked state
IndicatorLED.setPixelColor(0, 0, 0, 0);
IndicatorLED.setPixelColor(1, 0, 0, 0);
IndicatorLED.show();
delay(500);
IndicatorLED.setPixelColor(0, 0, 255, 0);
IndicatorLED.setPixelColor(1, 0, 255, 0); //RED
IndicatorLED.show();
delay(500);
IndicatorLED.setPixelColor(0, 0, 0, 0);
IndicatorLED.setPixelColor(1, 0, 0, 0);
IndicatorLED.show();
delay(500);
IndicatorLED.setPixelColor(0, 0, 255, 0);
IndicatorLED.setPixelColor(1, 0, 255, 0); //RED
IndicatorLED.show();
delay(500);
IndicatorLED.setPixelColor(0, 0, 0, 0);
IndicatorLED.setPixelColor(1, 0, 0, 0);
IndicatorLED.show();
setLockState(LOCKED);
}
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256; j++) {
for (i = 0; i < IndicatorLED.numPixels(); i++) {
IndicatorLED.setPixelColor(i, Wheel((i + j) & 255));
}
IndicatorLED.show();
delay(wait);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if (WheelPos < 85) {
return IndicatorLED.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos < 170) {
WheelPos -= 85;
return IndicatorLED.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return IndicatorLED.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}