#include <stdio.h>
#include <string.h>
#include "Keypad.h"
using namespace std;
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { A0, A1, A2, A3 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 13, 12, 11, 10 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
char buttonpressed;
int tempcounter = 0;
int temptemptempresult1;
char tempresult;
String finalresult;
String tempfinalresult1;
String tempfinalresult2;
String tempfinalresult3;
int finalresult1;
int finalresult2;
int finalresult3;
String tempcheck1;
String tempcheck2;
String tempcheck3;
int tempconfirm;
int tempconfirm1;
int tempconfirm2;
int tempconfirm3;
int ledred = 3;
int ledgreen = 5;
int ledblue = 6;
int red;
int green;
int blue;
int redinput;
int greeninput;
int blueinput;
int mappedred;
int mappedgreen;
int mappedblue;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
tempconfirm = 1;
mmt();
}
void loop() {
// put your main code here, to run repeatedly:
/*red = redinput;
green = greeninput;
blue = blueinput;
mappedred = (map(red, 0, 1023, 0, 255));
mappedgreen = (map(green, 0, 1023, 0, 255));
mappedblue = (map(blue, 0, 1023, 0, 255));
analogWrite(ledred, mappedred);
analogWrite(ledgreen, mappedgreen);
analogWrite(ledblue, mappedblue);
Serial.print("red = ");
Serial.print(mappedred);
Serial.print(" ");
Serial.print("green = ");
Serial.print(mappedgreen);
Serial.print(" ");
Serial.print("blue = ");
Serial.println(mappedblue);*/
char key = keypad.getKey();
if (key == 'A' || buttonpressed == 'A') {
clrserialmonitor();
buttonpressed = 'A';
while (buttonpressed == 'A'){
char key = keypad.getKey();
delay(10);
if(tempconfirm == 1 && key != NO_KEY && key != '*' && key != 'A' && key != 'B' && key != 'C' && key != 'D' && key != '#' && key != '0'){
char tempstring = key;
int tempcheck1 = tempstring - '0';
int result1 = tempcheck1;
char temptempresult = tempresult;
char tempresult = temptempresult + result1;
int finaltempresult = tempresult;
tempcounter += 1;
char tempcountuper;
Serial.println(result1);
Serial.println(tempcounter);
tempfinalresult1 += key;
char tempchar = key;
int temptempcheck1 = tempchar - '0';
int temptemptempresult1 = temptempcheck1;
Serial.println(temptemptempresult1);
/*char finalresult1 = tempfinalresult1;*/
delay(20);
if(temptemptempresult1 < 255 && tempcounter == 3){
Serial.println(tempfinalresult1);
buttonpressed = ' ';
}
if(temptemptempresult1 > 255 && tempcounter == 3){
Serial.println("over 255");
buttonpressed = ' ';
}
}
if(tempconfirm1 == 2 && key != NO_KEY && key != '*' && key != 'A' && key != 'B' && key != 'C' && key != 'D' && key != '#' && key != '0'){
char tempstring = key;
Serial.println(key);
}
if(key != NO_KEY && key != '*' && key != 'A' && key != 'B' && key != 'C' && key != 'D' && key != '#' && key != '0'){
char tempstring = key;
}
if(key == '*'){
buttonpressed = ' ';
Serial.print("canceling");
for(int i=0;i<3;i++){
Serial.print(".");
delay(1000);
}
Serial.println(" ");
mmt();
}
}
}
if (key == 'B') {
Serial.println(key);
}
if (key == 'C') {
Serial.println(key);
}
}
void mmt(void){
clrserialmonitor();
Serial.println("please press one of the following options");
Serial.println("A for changing Red color");
Serial.println("B for changing Green color");
Serial.println("C for changing Blue color");
}
void clrserialmonitor(void){
Serial.println("");
Serial.println("");
Serial.println("");
Serial.println("");
Serial.println("");
Serial.println("");
Serial.println("");
Serial.println("");
Serial.println("");
Serial.println("");
Serial.println("");
Serial.println("");
}