Go Down

Topic: Help with coding... (Read 2623 times) previous topic - next topic

R10_JR

This is a new code version of V0.1

Code V0.2:
Code: [Select]

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'#','0','*'}
};
byte rowPins[ROWS] = {12, 11, 10, 9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int VARone = 0;
int VARtwo = 0 ;
int VARthree = 0;
int One1 = 0;
int Two2 = 0;
int Three3 = 0;
int total = 0;

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(2,INPUT);
  pinMode(5,OUTPUT);
  pinMode(4,OUTPUT);
}

void loop()
  {
    // put your main code here, to run repeatedly:
    if (digitalRead(2))//Reset Loop
    {
      VARone = (0);
      VARtwo = (0);
      VARthree = (0);
      One1 = (0);
      Two2 = (0);
      Three3 = (0);
      total = (0);
    }
    else
    {
if(digitalRead(3))//Calculation loop
{

if(VARone == 1)//Runs calculation when there is only one variable
{
total = (One1);//Takes one inputted number like; '5'
}
else
{
if((VARone == 1)&&(VARtwo == 1))//Runs calculation when there is only two variables
{
total =  (((One1)*(10))+((Two2)));//Takes two inputted numbers and calculates like; '60'
}
else
{
if((VARone == 1)&&(VARtwo == 1)&&(VARthree== 1))//Runs calculation when there is only three variables
{
total = ((((One1)*(100))+((Two2)*(10)))+(Three3));//Takes three inputted numbers and calculates like; '111'
}
}
}
        }
else//keypad loop
        {
char key = keypad.getKey();
Serial.println(One1);
delay(11);
if((VARone)==(0))//Test if variable one is equal to 0
{
//Get key from 0 - 9 and set it to variable one
char key = keypad.getKey();
if(key != NO_KEY)
{
One1==(key);
VARone==1;
}
}
else
{
delay(11);
if(((VARone)==(1))&&((VARtwo)==(0)))//Test variable one is equal to 1, whilst variable two is equal to 0
{
//Get key from 0 - 9 and set it to variable two
char key = keypad.getKey();
if(key != NO_KEY)
{
Two2==(key);
VARtwo==1;
}
}
else
{
delay(11);
if(((VARone)==(1))&&((VARtwo)==(1))&&((VARthree)==(0)))//Test variable one and variable two is equal to 1, whilst variable three is equal to 0
{
//Get key from 0 - 9 and set it to variable three
char key = keypad.getKey();
if(key != NO_KEY)
{
Three3==(key);
VARthree==1;
}
}
else//loop
{
digitalWrite(4,HIGH);
analogWrite(5,255);
delay(11);
analogWrite(5,0);
digitalWrite(4,LOW);
delay((60000)/(total));//makes a delay, e.g. 60000/111 = 540.540540541ms
}
}
}
}
       
    }
}

R10_JR

Hello Everyone I am very grateful for the help and I have the full working code for you guys for this is a silent metronome which vibrates to a BPM and will help other people  will find this useful. Thanks for this everyone... :)

CODE PT.1? V.F
Code: [Select]

#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {12, 11, 10, 9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int VARdelay = 0;
int VARone = 0;
int VARtwo = 0;
int VARthree = 0;
int One1 = 0;
int Two2 = 0;
int VARtotal = 0;
void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(2,INPUT);
  pinMode(5,OUTPUT);
  pinMode(4,OUTPUT);
}
void loop()
 {
 // put your main code here, to run repeatedly:
 if((VARone)==(0))//Variable One: Calcuation and keypad setting from 0-9
 {
 delay(11);
 char key = keypad.getKey();
 Serial.println(VARdelay);
 if (key)
 {
 switch(key)
 {
 case '#':
 VARone = 1;
 VARtwo = 1;
 VARthree =1;
 break;
 case '0'://set variable one to this number
 One1 = 0;
 VARdelay = 60000;//set delay
 VARone = 1;
 break;
 case '1'://set variable one to this number
 One1 = 1;
 VARdelay = ((60000)/(1));//set delay
 VARone = 1;
 break;
 case '2'://set variable one to this number
 One1 = 2;
 VARdelay = ((60000)/(2));//set delay
 VARone = 1;
 break;
 case '3'://set variable one to this number
 One1 = 3;
 VARdelay = ((60000)/(3));//set delay
 VARone = 1;
 break;
 case '4'://set variable one to this number
 One1 = 4;
 VARdelay = ((60000)/(4));//set delay
 VARone = 1;
 break;
 case '5'://set variable one to this number
 One1 = 5;
 VARdelay = ((60000)/(5));//set delay
 VARone = 1;
 break;
 case '6'://set variable one to this number
 One1 = 6;
 VARdelay = ((60000)/(6));//set delay
 VARone = 1;
 break;
 case '7'://set variable one to this number
 One1 = 7;
 VARdelay = ((60000)/(7));//set delay
 VARone = 1;
 break;
 case '8'://set variable one to this number
 One1 = 8;
 VARdelay = ((60000)/(8));//set delay
 VARone = 1;
 break;
 case '9'://set variable one to this number
 One1 = 9;
 VARdelay = ((60000)/(9));//set delay
 VARone = 1;
 break;
 }
 }
 }
 else
 {
 if(((VARone)==(1))&&((VARtwo)==(0)))//Variable Two: Calculation and keypad setting from 0-9
 {
 delay(11);
 char key = keypad.getKey();
 Serial.println(VARdelay);
 if (key)
 {
 switch (key)
 {
 case '#':
 VARtwo = 1;
 VARthree =1;
 break;
 case '0'://set variable one to this number
 Two2 = 0;
 VARtotal = (((One1)*(10))+(0));//Caculation. If there is a previous calculation overwrite it
 VARdelay = ((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARtwo = 1;
 break;
 case '1'://set variable one to this number
 Two2 = 1;
 VARtotal = (((One1)*(10))+(1));//Caculation. If there is a previous calculation overwrite it
 VARdelay = ((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARtwo = 1;
 break;
 case '2'://set variable one to this number
 Two2 = 2;
 VARtotal = (((One1)*(10))+(2));//Caculation. If there is a previous calculation overwrite it
 VARdelay = ((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARtwo = 1;
 break;
 case '3'://set variable one to this number
 Two2 = 3;
 VARtotal = (((One1)*(10))+(3));//Caculation. If there is a previous calculation overwrite it
 VARdelay = ((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARtwo = 1;
 break;
 case '4'://set variable one to this number
 Two2 = 4;
 VARtotal = (((One1)*(10))+(4));//Caculation. If there is a previous calculation overwrite it
 VARdelay = ((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARtwo = 1;
 break;
 case '5'://set variable one to this number
 Two2 = 5;
 VARtotal = (((One1)*(10))+(5));//Caculation. If there is a previous calculation overwrite it
 VARdelay = ((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARtwo = 1;
 break;
 case '6'://set variable one to this number
 Two2 = 6;
 VARtotal = (((One1)*(10))+(6));//Caculation. If there is a previous calculation overwrite it
 VARdelay = ((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARtwo = 1;
 break;
 case '7'://set variable one to this number
 Two2 = 7;
 VARtotal = (((One1)*(10))+(7));//Caculation. If there is a previous calculation overwrite it
 VARdelay = ((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARtwo = 1;
 break;
 case '8'://set variable one to this number
 Two2 = 8;
 VARtotal = (((One1)*(10))+(8));//Caculation. If there is a previous calculation overwrite it
 VARdelay = ((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARtwo = 1;
 break;
 case '9'://set variable one to this number
 Two2 = 9;
 VARtotal = (((One1)*(10))+(9));//Caculation. If there is a previous calculation overwrite it
 VARdelay = ((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARtwo = 1;
 break;
 }
 }
 }
 else
 {
 if(((VARone)==(1))&&((VARtwo)==(1))&&((VARthree)==(0)))//Variable Three: Calculation and keypad setting from 0-9
 {
 delay(11);
 char key = keypad.getKey();
 Serial.println(VARdelay);
 if (key)
 {
 switch (key)
 {
 case '#':
 VARthree = 1;
 break;
 case '0'://set variable one to this number
 VARtotal = (((One1)*(100))+((Two2)*(10))+(0));//Caculation. If there is a previous calculation overwrite it
 VARdelay =((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARthree = 1;
 break;
 case '1'://set variable one to this number
 VARtotal = (((One1)*(100))+((Two2)*(10))+(1));//Caculation. If there is a previous calculation overwrite it
 VARdelay =((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARthree = 1;
 break;
 case '2'://set variable one to this number
 VARtotal = (((One1)*(100))+((Two2)*(10))+(2));//Caculation. If there is a previous calculation overwrite it
 VARdelay =((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARthree = 1;
 break;
 case '3'://set variable one to this number
 VARtotal = (((One1)*(100))+((Two2)*(10))+(3));//Caculation. If there is a previous calculation overwrite it
 VARdelay =((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARthree = 1;
 break;
 case '4'://set variable one to this number
 VARtotal = (((One1)*(100))+((Two2)*(10))+(4));//Caculation. If there is a previous calculation overwrite it
 VARdelay =((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARthree = 1;
 break;
 case '5'://set variable one to this number
 VARtotal = (((One1)*(100))+((Two2)*(10))+(5));//Caculation. If there is a previous calculation overwrite it
 VARdelay =((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARthree = 1;
 break;
 case '6'://set variable one to this number
 VARtotal = (((One1)*(100))+((Two2)*(10))+(6));//Caculation. If there is a previous calculation overwrite it
 VARdelay =((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARthree = 1;
 break;
 case '7'://set variable one to this number
 VARtotal = (((One1)*(100))+((Two2)*(10))+(7));//Caculation. If there is a previous calculation overwrite it
 VARdelay =((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARthree = 1;
 break;
 case '8'://set variable one to this number
 VARtotal = (((One1)*(100))+((Two2)*(10))+(8));//Caculation. If there is a previous calculation overwrite it
 VARdelay =((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARthree = 1;
 break;
 case '9'://set variable one to this number
 VARtotal = (((One1)*(100))+((Two2)*(10))+(9));//Caculation. If there is a previous calculation overwrite it
 VARdelay =((60000)/(VARtotal));//Set delay. If there is a previous delay overwrite it
 VARthree = 1;
 break;
 }
 }
 }
 else
 {
 if(digitalRead(2))//Reset all int
 {
 VARone = 0;
 VARtwo = 0;
 VARthree = 0;
 One1 = 0;
 Two2 = 0;
 VARtotal = 0;
 VARdelay = 0;
 }
 else
 {
 Serial.println(1337);//LEET
 Serial.println(VARdelay);
 digitalWrite(5,HIGH);
 digitalWrite(4,255);
 delay(36);
 digitalWrite(4,0);
 digitalWrite(5,LOW);
 delay(VARdelay);
 Serial.println(1337);//LEET
 }
 }
 }
 }
 }

AWOL


Go Up