0
I must create a program that commands a hardware in which I have connected on 3 different ports of the Arduino a circuit containing 3 Leds. The program must ascend these leds in binary order.
I have two functions ready, the first function "incrementaDigito"
has 4 variables; "base"
which refers to the basis on which we are operating, in this example a binary basis, the vector "numero[]"
, a vector with nths positions that will be used to store the binary value, "k"
is the variable used to update the digit of each position of that binary value stored in the vector, and "n"
is the number of elements that the vector "número[]"
will contain. This function is to update each position of the vector in ascending order, while the "numero"
is smaller than the "base"
there is an increment in the variable "k"
and a false result is returned. Once the "number" is equal to the base, the function assigns zero to "k"
and returns a true result.
The function "incrementaNumero"
has the variables "base"
, "numero"
, "n"
. the variable is defined "k"
as a function of "n"
, the number of elements in the vector "numero[]"
. If the previous function returns false nothing happens, when return true there is a decrease in k.
I have to finish the Loop and Setup of my program, and do the documentation, can help me relate these functions so 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);
}