Question

In: Computer Science

What does each line in the code?? Please unsigned Long timer1; unsigned Long button_dbnc_tmr = 0;...

What does each line in the code?? Please

unsigned Long timer1;
unsigned Long button_dbnc_tmr = 0;
const int User_Button = 2;
const int USER_LED_Pin = 13;
bool allow_change = 0;
int counter = 0;
int state;
void read_state_from_memory(void);
void write_state_to_memory(void);
void turnoff(void);
void flash_1s(void);
void flash_2s(void);
void flash_3s(void);

void setup()
{
read_state_from_memory();
pinMode(USER_LED_Pin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
timers();
if(digitalRead(User_Button) == 1)
{
if(allow_change == 1)
{
state++;
Serial.println(counter);
Serial.println(state);
allow_change = 0;
if(state > 3)
state = 0;
write_state_to_memory();
}
}
}
else
{    counter = 0;
    allow_change = 1;
button_dbnc_tmr = 0;
}
switch(state_
{
case 0:
turn off();
break;
case 1:
flash_1s();
break;
case 2:
flash_2s();
break;
case 3:
flash_3s();
break;
}
}
void turnoff()
{

//complete by me

}
void flash_1s()
{
//complete by me

}
void flash_2s()
{
//complete by me

}
void flash_3s()
{
//complete by me

}
void timers(void)
{
static unsigned Long ms_runtime;
static int one_ms_timer;

if(millis() > (ms_runtime + 1))
{   ms_runtime = ms_runtime + 1;
one_ms_timer++;
}
else if(ms_runtime > millis())x
ms_runtime = millis();

if(one_ms_timer > 99)
{   one_ms_timer = 0;
button_dbnc_tmr++;
timer1++;
}
}
void read_state_from_memory ()
{
//to be completed by me
}
void write_state_to_memory()
{
//to be completed by me
}

Solutions

Expert Solution

The purpose of each line is added as command line.

// Declare global variable timer1 as unsigned Long (32 bit size)

unsigned Long timer1;

// Declare global variable button_dbnc_tmr as unsigned Long and initialize it to 0

unsigned Long button_dbnc_tmr = 0;

// Declare constant User_Button as integer type and initialize it to 2

const int User_Button = 2;

// Declare constant USER_LED_Pin as integer type and initialize it to 13

const int USER_LED_Pin = 13;

// Declare boolean variable allow_change and initialize it to 0

bool allow_change = 0;

// Declare integer variable counter and initialize it to 0

int counter = 0;

// Declare integer variable state

int state;

// Declare user defined function read_state_from_memory with void parameter and no return values

void read_state_from_memory(void);

// Declare user defined function write_state_to_memory with void parameter and no return values

void write_state_to_memory(void);

// Declare user defined function turnoff with void parameter and no return values

void turnoff(void);

// Declare user defined function flash_1s with void parameter and no return values

void flash_1s(void);

// Declare user defined function flash_2s with void parameter and no return values

void flash_2s(void);

// Declare user defined function flash_3s with void parameter and no return values

void flash_3s(void);

// Define a user defined function setup to setup Arduino

//function setup which is used to setup the Arduino

void setup()

{

    //calling the function read_state_from_memory()

read_state_from_memory();

//calling the function pinMode() as Pins configured as OUTPUT mode , We pass USER_LED_Pin which is we declared in the begining

//Here we pass pin as USER_LED_Pin and the mode as OUTPUT

pinMode(USER_LED_Pin, OUTPUT);

//Serial.begin(9600) passes the value 9600 to the speed parameter. This tells the Arduino to get ready to exchange messages with the Serial Monitor at a data rate of 9600 bits per second.

Serial.begin(9600);

}

//// Define a user defined function loop()

void loop()

{

    //calling the function timers()

timers();

//digitalRead() function will read the value from digital pin User_Button and return HIGH or LOW

if(digitalRead(User_Button) == 1)

{

    //true block

    //check the value in the variable allow_change is 1?

if(allow_change == 1)

{

    //increase value of state

state++;

//Serial.println() function will print the counter value with a newline character

Serial.println(counter);

//Serial.println() function will print the state value with a newline character

Serial.println(state);

// change the value of allow_change to zero

allow_change = 0;

//change the value of state to zero if the current value of variable state is greater than 3

if(state > 3)

{

state = 0;

//call function write_state_to_memory()

write_state_to_memory();

}

}

}

// else case of first if clause

else

{

    //change the values of counter , allow_change,button_dbnc_tmr

    counter = 0;

    allow_change = 1;

button_dbnc_tmr = 0;

}

//switch block for state variable, the functions turn_off(),flash_1s(),flash_2s() or flash_3s() will be called according to the value in state variable;

switch(state)

{

case 0:

turn_off();

break;

case 1:

flash_1s();

break;

case 2:

flash_2s();

break;

case 3:

flash_3s();

break;

}

}

//defenition of the function turnoff() that might be contain the code to turn off the Arduino

void turnoff()

{

//complete by me

}

//defenition of the function flash_1s that does not return aby value

void flash_1s()

{

//complete by me

}

//defenition of the function flash_2s that does not return aby value

void flash_2s()

{

//complete by me

}

//defenition of the function flash_2s that does not return aby value

void flash_3s()

{

//complete by me

}

// user defined function timers

void timers(void)

{

    //declare two static variables Long ms_runtime and one_ms_timer

static unsigned Long ms_runtime;

static int one_ms_timer;

//the function millis() will return the number of milliseconds at the time, the Arduino board begins running the current program

//the time will compared with the value ms_runtime + 1, If the running time is higher than ms_runtime + 1.

if(millis() > (ms_runtime + 1))

{   

    //true cawse :value of ms_runtime and one_ms_timer will be incrimented

    ms_runtime = ms_runtime + 1;

one_ms_timer++;

}

//else check the ms_runtime is greater than the number of milliseconds at the time, the Arduino board begins running the current program

//if it is true the value of ms_runtime is changes to the Arduino running time

else if(ms_runtime > millis())x

ms_runtime = millis();

//check the value one_ms_timer which is updated in the true case of above if condition ,is greater than 100, then it will round to zero

if(one_ms_timer > 99)

{ one_ms_timer = 0;

// the value of button_dbnc_tmr and timer1 is incrimented by 1

button_dbnc_tmr++;

timer1++;

}

}

//defenition of function read_state_from_memory ()

void read_state_from_memory ()

{

//to be completed by me

}

//defenition of function write_state_to_memory()

void write_state_to_memory()

{

//to be completed by me

}


Related Solutions

Arduino Uno code, Please explain what does this code do? unsigned long ms_runtime; int one_ms_timer; //define...
Arduino Uno code, Please explain what does this code do? unsigned long ms_runtime; int one_ms_timer; //define all timers as unsigned variables unsigned long timer1 = 0; // timer1 increments every 100ms = 0.1s const int USER_LED_OUTPUT = 13; const int USER_BUTTON_INPUT = 2; void setup() { // initialize the digital pin as an output. pinMode(USER_LED_OUTPUT, OUTPUT); pinMode(USER_BUTTON_INPUT, INPUT); Serial.begin(9600); } void loop() { // run loop forever static int state, old_state,counter; timers(); // logic for state change if(state == 0)...
. What does each line of the following code do? fsrPin = ‘A4’; ledPin = ‘D4’;...
. What does each line of the following code do? fsrPin = ‘A4’; ledPin = ‘D4’; anArduinoObj = arduino(); forceVoltage = readVoltage(anArduinoObj, fsrPin); if forceVoltage > 4.0 writeDigitalPin(anArduinoObj, ledPin, 1); end Based on the Adafruit pages related to their round FSR sensor, what is the required force to read a voltage greater than 4V?
Can you please explain in detail what each line of code stands for in the Main...
Can you please explain in detail what each line of code stands for in the Main method import java.util.Scanner; public class CashRegister { private static Scanner scanner = new Scanner(System.in); private static int dollarBills[] = {1, 2, 5, 10, 20, 50, 100}; private static int cents[] = {25, 10, 5, 1}; public static void main(String[] args) { double totalAmount = 0; int count = 0; for (int i = 0; i < dollarBills.length; i++) { count = getBillCount("How many $"...
please let me know reference of this MATLAB code. please explain this code line by line....
please let me know reference of this MATLAB code. please explain this code line by line. . . N=256; %% sampling number n=linspace(0,1,N); fs=1/(n(2)-n(1)); x=5*(sin((2*pi*10*n))); %% create signal N=length(x); f=[-fs/2:fs/N:fs/2-fs/N]; subplot(211) plot(f,fftshift(abs(fft(x)))); title('|G(f)|');grid; xlabel('frequency'); ylabel('|G(f)|'); %Zero padding xx=[zeros(1,128) x zeros(1,128)]; N=length(xx); f=[-fs/2:fs/N:fs/2-fs/N]; subplot(212) plot(f,fftshift(abs(fft(xx)))); title('|Gz(f)|');grid; xlabel('frequency'); ylabel('|Gz(f)|');
Can someone please write clear and concise comments explaining what each line of code is doing...
Can someone please write clear and concise comments explaining what each line of code is doing for this program in C. I just need help tracing the program and understand what its doing. Thanks #include <stdio.h> #include<stdlib.h> #include<unistd.h> #include<sys/wait.h> int join(char *com1[], char *com2[]) {    int p[2], status;    switch (fork()) {        case -1:            perror("1st fork call in join");            exit(3);        case 0:            break;        default:...
Python 3 can you explain what every single line of code does in simple terms please...
Python 3 can you explain what every single line of code does in simple terms please so basically # every single line with an explanation thanks def longest(string): start = 0;end = 1;i = 0; while i<len(string): j = i+1 while j<len(string) and string[j]>string[j-1]: j+=1 if end-start<j-i: end = j start = i i = j; avg = 0 for i in string[start:end]: avg+=int(i) print('The longest string in ascending order is',string[start:end]) print('The average is',avg/(end-start)) s = input('Enter a string ')...
What does each line of this python code do? import datetime import getpass print("\n\nFinished execution at...
What does each line of this python code do? import datetime import getpass print("\n\nFinished execution at ", datetime.datetime.now()) print(getpass.getuser())
a. What will be the output of LINE A in code “a” and output of code...
a. What will be the output of LINE A in code “a” and output of code “b”? Also write reasons for the outputs. a. #include <sys/types.h> #include <stdio.h> #include <unistd.h> int value = 3; int main() { pid_t pid; pid = fork(); if (pid = = 0) {/* child process */} value += 233; return 0; } else if (pid > 0) {/* parent process */} wait(NULL); printf(“PARENT: value = %d”, value); /* LINE A */ return 0; } }...
What is the output of the code below? After each line that has a cout, write...
What is the output of the code below? After each line that has a cout, write what the output of the code is. See example in code below. int i = 2, j = 1, k = i + j; cout << k << endl; ➔ 3 double d = 2.99, e = 1, f = d + e; cout << f << endl; double q = 1.50; cout << q/3 << endl; cout << 6.0/4 << endl; char c...
explain the code for a beginner in c what each line do Question 3. In the...
explain the code for a beginner in c what each line do Question 3. In the following code, answer these questions: Analyze the code and how it works? How can we know if this code has been overwritten? Justify how? #include <stdlib.h> #include <unistd.h> #include <stdio.h> int main(int argc, char **argv) { int changed = 0; char buff[8]; while (changed == 0){ gets(buff); if (changed !=0){ break;} else{     printf("Enter again: ");     continue; } }      printf("the 'changed' variable...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT