I must create a program that commands a hardware in which I have connected in 3 different ports of the arduino a circuit containing 3 leds. The program should raise these LEDs in binary order.
I have two functions ready, the first function "incrementaDigito"
has 4 variables; "base"
which refers to the base on which we are operating, in this example a binary base, the vector "numero[]"
, a vector with nth positions that will be used to store the binary value, "k"
is the variable used to update the number of each position of that binary value stored in the vector, and "n"
is the number of elements that the "número[]"
vector will contain. This function has the function of updating each position of the vector in ascending order, while "numero"
is less than "base"
there is an increment in the "k"
variable and a false result is returned. From the moment the "number" is equal to the base, the function assigns zero to "k"
and returns a true result.
The "incrementaNumero"
function has the variables "base"
, "numero"
, "n"
. we define the variable "k"
as a function of "n"
, the number of elements in the "numero[]"
vector. If the previous function returns false nothing happens, when it returns true there is a decrease in k.
I have to finish my program's Loop and Setup, and do the documentation, can you help me relate these functions so that I can finish?
//CÓDIGO
#define DELAY 400
#define NUMERO[0,0,0]
#define BASE 2
# define N 3
bool incrementaDigito (unsigned base, unsigned numero[], unsigned k, unsigned n){
if (numero < base){
numero[k]++;
return false;
}
else{
numero [k] =0;
return true;
}
}
void incrementaNumero (unsigned base, unsigned numero[], unsigned n){
unsigned k = n-1;
do{
if(incrementaDigito(base, numero, k, n)==false) break;
else k--;
}
while(k>=0);
}
int ledPin1 = 11;
int ledPin2 = 12;
int ledPin3 = 13;
void setup()
{
pinMode(ledPin1 , OUTPUT);
pinMode(ledPin2 , OUTPUT);
pinMode(ledPin3 , OUTPUT);
}
void loop()
{
unsigned numero[];
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
for(int k=0;k<2;k++){
if(k==1){
j++;
k=0;}
if(j==1){
i++;
j=0;
k=0;}
if(i==1){
i=0;
j=0;
k=0;}
}
}
}
digitalWrite(ledPin1, );
digitalWrite(ledPin2, );
digitalWrite(ledPin3, );
delay(DELAY);
}