#include <FastLED.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <EEPROM.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
// How many leds in your strip?
#define NUM_LEDS 8
// For led chips like WS2812, which have a data line, ground, and power, you just
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
// Clock pin only needed for SPI based chipsets when not using hardware SPI
#define DATA_PIN 6
bool comma;
int cnt;
byte pick[100] ={3,6,12,9,3,6,12,9,3,6,12,9,12,6,3,9,12,6,3,9,12,6,3,9,} ;
byte length =24;
byte value;
int tmp;
// Define the array of leds
CRGB leds[NUM_LEDS];
const uint8_t ROWS = 4; // number of rows in the keyboard
const uint8_t COLS = 4; // number of collumns in the keypad
char keys[ROWS][COLS] = { // the keypad charater matrix (there are 4 nul keys)
{ 1, 2, 3, 'U' }, // top row numbers 1 to 3 and a null
{ 4, 5, 6, 'D' }, // 2nd row numbers 4 to 6 and a null
{ 7, 8, 9, 'S' }, // 3rd row numbers 7 to 9 and a null
{ 'R', ' ', '<', '>' } // 4th row number 0, a null D for delete and C for clear
};
// note that American Standard Code for Information Interchange (ASCII)
// is used for zero, as zero would be interpreted as no key pressed
uint8_t colPins[COLS] = { A3, A2, A1, A0 }; // Pins connected to collumns 1 to 4
uint8_t rowPins[ROWS] = { 5, 4, 3, 2 }; // Pins connected to rows 1 to 4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// make the keyboard map used by keyboard.h from the above information
void setup() {
value = byte (EEPROM.read(0));
//value = 30;
if (value !=255)
{
length=value;
for (cnt=0; cnt<=length; cnt++)
{
byte value=byte (EEPROM.read(cnt+2));
pick [cnt] = value;
}
value=byte(EEPROM.read(1));
cnt=value ;
}
FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical
lcd.begin(20, 4);
lcd.setCursor (0,0) ;
lcd.print (" Weaving controler");
//delay(3000);
disp(pick[cnt]);
scrn(pick[cnt]);
}
void loop()
{
char key = keypad.getKey(); // get the value of any pressed key from keyboard.h
if (key != NO_KEY)
{
// lcd.setCursor (0,1);
// lcd.print (key);
if (key=='U')
{
length ++;
if (length >99) length = 99;
disp (pick[cnt]);
scrn(pick[cnt]);
}
if (key=='D')
{
length --;
if (length < 5) length = 5;
disp (pick[cnt]);
scrn(pick[cnt]);
}
if (key=='>')
{
cnt++;
if (cnt>=length) cnt=0;
disp (pick[cnt]);
scrn(pick[cnt]);
}
if (key=='<')
{
cnt--;
if (cnt<0) cnt=length-1;
disp(pick[cnt]);
scrn(pick[cnt]);
}
if(key==1)
{
pick[cnt]=pick[cnt] ^ 1;
disp(pick[cnt]);
scrn(pick[cnt]);
}
if(key==2)
{
pick[cnt]=pick[cnt] ^ 2;
disp(pick[cnt]);
scrn(pick[cnt]);
}
if(key==3)
{
pick[cnt]=pick[cnt] ^ 4;
disp(pick[cnt]);
scrn(pick[cnt]);
}
if(key==4)
{
pick[cnt]=pick[cnt] ^ 8;
disp(pick[cnt]);
scrn(pick[cnt]);
}
if(key==5)
{
pick[cnt]=pick[cnt] ^ 16;
disp(pick[cnt]);
scrn(pick[cnt]);
}
if(key==6)
{
pick[cnt]=pick[cnt] ^ 32;
disp(pick[cnt]);
scrn(pick[cnt]);
}
if(key==7)
{
pick[cnt]=pick[cnt] ^ 64;
disp(pick[cnt]);
scrn(pick[cnt]);
}
if(key==8)
{
pick[cnt]=pick[cnt] ^ 128;
disp(pick[cnt]);
scrn(pick[cnt]);
}
if (key=='S')
{
value=length;
EEPROM.update (0,value);
value=cnt;
EEPROM.update(1,value);
for (tmp=0; tmp<=length; tmp++)
{
value=pick[tmp];
EEPROM.write(tmp+2,value);
}
lcd.clear();
lcd.print("Program Saved");
delay (4000);
disp(pick[cnt]);
scrn(pick[cnt]);
}
if (key=='R')
{
value= byte (EEPROM.read(0));
if (value !=255)
{
length=value;
value=byte(EEPROM.read(1));
cnt=value;
for (tmp=0; tmp<=length; tmp++)
{
value= byte (EEPROM.read(tmp+2));
pick[tmp]=value;
}
lcd.clear();
lcd.print("Program Restored");
delay (4000);
disp(pick[cnt]);
scrn(pick[cnt]);
}
}
}
}
int scrn(int val)
{
lcd.clear();
//lcd.print ("Weaving controler");
lcd.setCursor (0,0);
lcd.print("Lngth "); lcd.print(length);
lcd.setCursor(9,0);
lcd.print ("Pick "); lcd.print (cnt+1);
lcd.setCursor(0,1);
lcd.print(" "); //lcd.print (val);
if (val >= 127)
{
lcd.setCursor(15,1);
lcd.print(8);
val=val-128;
//if (val != 0) lcd.print (",");
}
if (val >= 64)
{
lcd.setCursor(13,1);
lcd.print(7);
val=val-64;
//if (val != 0) lcd.print (",");
}
if (val >= 32)
{
lcd.setCursor(11,1);
lcd.print(6);
val=val-32;
//if (val != 0) lcd.print (",");
}
if (val >= 16)
{
lcd.setCursor(9,1);
lcd.print(5);
val=val-16;
//if (val != 0) lcd.print (",");
}
if (val >= 8)
{
lcd.setCursor(7,1);
lcd.print(4);
val=val-8;
//if (val != 0) lcd.print (",");
}
if (val >= 4)
{
lcd.setCursor(5,1);
lcd.print(3);
val=val-4;
//if (val != 0) lcd.print (",");
}
if (val >= 2)
{
lcd.setCursor(3,1);
lcd.print(2);
val=val-2;
//if (val != 0) lcd.print (",");
}
if (val >= 1)
{
lcd.setCursor(1,1);
lcd.print(1);
}
}
int disp(int val)
{
// Turn the LED on, then pause
if (val>=128)
{
leds[7]= CRGB::CRGB::Yellow;
val=val-128;
}
else
leds[7]=CRGB::Black;
if (val>=64)
{
leds[3]= CRGB::Yellow;
val=val-64;
}
else
leds[3]=CRGB::Black;
if (val>=32)
{
leds[6]= CRGB::Yellow;
val=val-32;
}
else
leds[6]=CRGB::Black;
if (val>=16)
{
leds[2]= CRGB::CRGB::Yellow;
val=val-16;
}
else
leds[2]=CRGB::Black;
if (val>=8)
{
leds[5]= CRGB::Yellow;
val=val-8;
}
else
leds[5]=CRGB::Black;
if (val>=4)
{
leds[1]= CRGB::Yellow;
val=val-4;
}
else
leds[1]=CRGB::Black;
if (val>=2)
{
leds[4]= CRGB::Yellow;
val=val-2;
}
else
leds[4]=CRGB::Black;
if (val>=1)
{
leds[0]= CRGB::Yellow;
}
else leds[0]=CRGB::Black;
FastLED.show();
}