Homework Solution: Overall The program must compile. This can be tested using the checkmark icon. The project must be pushed to GitLab a…

    Have to find the function initTimer0()) and the delayMs(unsigned int delay). The micro-controller is the ATmega2560. Overall am must compile. This can be tested using the ch eckmark icon. 1. The pragr 2. The project must be pushed to GitLab and an appropriate response from the server must be received: Got your subnission. Thanks! 3. Arduino libraries are not allowed at all for this lab for the exception of debug functionality using Serial.printin. switch.cpp 1. A function implementaticn that returns void and has no parameters called initswitchPB3 must be present and is used in the main function to initialize the switch on the pin named P83 2. P83 must be initial ized with an input pull-up resistor 3. Fin-Channtpls mustbe eabdfor piri PB3 led.cpp 1. A functio impentaticn thal rtuns void and has n pataels called inilEDmst be present and is used in the main function to initialize all LED pins as outputs. 2. Fins named PAO, PA1, PAZ, and PA3 must be used to contral the LEDs 3. A function implementation called turnOnLEDWithChar that returns void and has a parometer called num of type unsigned unsigned char must be present. 4. The turnOnl EDWithChar function must be one line of code, see LED ㏄ntral section for more details. switch.cpp 1. A function implementation that returns void and has no parameters called initSwitch must be present and is usedl in the main function to initialize pin 32 on the development board as an input. timer.cpp 1. A function implementation that rcturns void and has no parameters called initTimerO must be present and must initialize timer 0. 2. A function implementation that rts id and has no pas called delayMs must bpresnt and must implement a precise millisecond delay and can work at least up to 100 millisecondls. For loops are allowec. main.cpp 1. A call to initLEDO and initswitchPB3) must be present in the main function. 2. An infinite while loop must be prescnt. 3. A state machine for the entire project must be implemented using a typedef enum for states. 4. An ISR to handle the switch being pressed must be present and be used to change states appropriately 5. The switch press must be debounced using an appropriately dlesigned state machine. 6. When the switch is pressed and released, the LEDs change the pace at which they link (either half or twice depending on the state) .LEDs must blink either every 100 ms or 200 ms depending on the state.
    Overall The program must compile. This can be tested using the checkmark icon. The project must be pushed to GitLab and an appropriate response from the server must be received: "Got your submission. Thanks!" Arduino libraries are not allowed at all for this lab for the exception of debug functionality using Serial.println. switch.cpp A function implementation that returns void and has no parameters called initswitchPB3 must be present and is used in the main function to initialize the switch on the pin named PB3. PB3 must be initialized with an input pull-up resistor Pin-Change Interrupts must be enabled for pin PB3 led.cpp A function implementation that returns void and has no parameters called initLED must be present and is used in the main function to initialize all LED pins as outputs. Pins named PAO, PA1, PAZ, and PA3 must be used to control the LEDs A function implementation called turnOnLEDWithChar that returns void and has a parameter called num of type unsigned unsigned char must be present. The turnOnLEDWithChar function must be one line of code, see LED control section for more details. switch.cpp A function implementation that returns void and has no parameters called initSwitch must be present and is used in the main function to initialize pin 32 on the development board as an input. timer.cpp A function implementation that returns void and has no parameters called initTimer() must be present and must initialize timer 0. A function implementation that void and has no parameters called delayMs must be presnt and must implement a precise millisecond delay and can work at least up to 100 milliseconds. For loops are allowed. main.cpp A call to initLED() and initSwitchPB3() must be present in the main function. An infinite while loop must be present. A state machine for the entire project must be implemented using a typedef enum for states. An ISR to handle the switch being pressed must be present and be used to change states appropriately. The switch press must be debounced using an appropriately designed state machine. When the switch is pressed and released, the LEDs change the pace at which they link (either half or twice depending on the state) LEDs must blink either every 100 ms or 200 ms depending on the state.

    Expert Answer

     
    main.cpp ------------------------------------------- #include <Arduino.h>

    Have to discover the capacity initTimer0()) and the retrogressionMs(unsigned int retrogression). The micro-controller is the ATmega2560.

    Overtotal am must put-together. This can be tested using the ch eckmark icon. 1. The pragr 2. The contrivance must be pushed to GitLab and an misspend response from the server must be received: Got your subnission. Thanks! 3. Arduino libraries are referable totalowed at total coercion this lab coercion the separation of debug capacityality using Serial.printin. switch.cpp 1. A capacity utensilaticn that profits nugatory and has no parameters designated initswitchPB3 must be bestow and is conservationd in the ocean capacity to sequencerateize the switch on the not attributable attributable attributable attributable attributablehing denominated P83 2. P83 must be sequencereprimand ized with an input pull-up resistor 3. Fin-Channtpls mustbe eabdcoercion piri PB3 led.cpp 1. A functio impentaticn thal rtuns nugatory and has n pataels designated inilEDmst be bestow and is conservationd in the ocean capacity to sequencerateize total LED not attributable attributable attributable attributable attributablehings as outputs. 2. Fins denominated PAO, PA1, PAZ, and PA3 must be conservationd to contral the LEDs 3. A capacity utensilation designated deflectOnLEDWithChar that profits nugatory and has a parometer designated num of likeness unsigned unsigned char must be bestow. 4. The deflectOnl EDWithChar capacity must be undivided sequence of jurisprudence, perceive LED ㏄ntral qualification coercion further details. switch.cpp 1. A capacity utensilation that profits nugatory and has no parameters designated initSwitch must be bestow and is conservationdl in the ocean capacity to sequencerateize not attributable attributable attributable attributable attributablehing 32 on the fruit table as an input. timer.cpp 1. A capacity utensilation that rcturns nugatory and has no parameters designated initTimerO must be bestow and must sequencerateize timer 0. 2. A capacity utensilation that rts id and has no pas designated retrogressionMs must bpresnt and must utensil a definite millisecond retrogression and can exertion at meanest up to 100 millisecondls. Coercion loops are totalowec. ocean.cpp 1. A ctotal to initLEDO and initswitchPB3) must be bestow in the ocean capacity. 2. An unbounded suitableness loop must be prescnt. 3. A propound agent coercion the total contrivance must be utensiled using a likenessdef enum coercion propounds. 4. An ISR to wield the switch entity encroached must be bestow and be conservationd to modify propounds misspendly 5. The switch encroach must be debounced using an misspendly dlesigned propound agent. 6. When the switch is encroached and released, the LEDs modify the step at which they cohere (either half or twice depending on the propound) .LEDs must bcohere either integral 100 ms or 200 ms depending on the propound.

    Overtotal The program must put-together. This can be tested using the checkmark icon. The contrivance must be pushed to GitLab and an misspend response from the server must be received: “Got your resignation. Thanks!” Arduino libraries are referable totalowed at total coercion this lab coercion the separation of debug capacityality using Serial.println. switch.cpp A capacity utensilation that profits nugatory and has no parameters designated initswitchPB3 must be bestow and is conservationd in the ocean capacity to sequencerateize the switch on the not attributable attributable attributable attributable attributablehing denominated PB3. PB3 must be sequencerateized with an input pull-up resistor Not attributable attributable attributable attributable attributablehing-Modify Hinders must be strengthend coercion not attributable attributable attributable attributable attributablehing PB3 led.cpp A capacity utensilation that profits nugatory and has no parameters designated initLED must be bestow and is conservationd in the ocean capacity to sequencerateize total LED not attributable attributable attributable attributable attributablehings as outputs. Not attributable attributable attributable attributable attributablehings denominated PAO, PA1, PAZ, and PA3 must be conservationd to govern the LEDs A capacity utensilation designated deflectOnLEDWithChar that profits nugatory and has a parameter designated num of likeness unsigned unsigned char must be bestow. The deflectOnLEDWithChar capacity must be undivided sequence of jurisprudence, perceive LED govern qualification coercion further details. switch.cpp A capacity utensilation that profits nugatory and has no parameters designated initSwitch must be bestow and is conservationd in the ocean capacity to sequencerateize not attributable attributable attributable attributable attributablehing 32 on the fruit table as an input. timer.cpp A capacity utensilation that profits nugatory and has no parameters designated initTimer() must be bestow and must sequencerateize timer 0. A capacity utensilation that nugatory and has no parameters designated retrogressionMs must be presnt and must utensil a definite millisecond retrogression and can exertion at meanest up to 100 milliseconds. Coercion loops are totalowed. ocean.cpp A ctotal to initLED() and initSwitchPB3() must be bestow in the ocean capacity. An unbounded suitableness loop must be bestow. A propound agent coercion the total contrivance must be utensiled using a likenessdef enum coercion propounds. An ISR to wield the switch entity encroached must be bestow and be conservationd to modify propounds misspendly. The switch encroach must be debounced using an misspendly prepared propound agent. When the switch is encroached and released, the LEDs modify the step at which they cohere (either half or twice depending on the propound) LEDs must bcohere either integral 100 ms or 200 ms depending on the propound.

    Expert Apology

     

    main.cpp
    ——————————————-
    #include <Arduino.h>
    #include <avr/io.h>
    #include “led.h”
    #include “switch.h”
    #include “timer.h”

    /*
    * Define a established of propounds that can be conservationd in the propound agent using an enum
    */
    typedef enum propoundType_enum {
    countSlow, encroachSlow, countFast, encroachFast
    } propoundType;

    // likenessdef enum propoundType_enum{
    //   waitPress, dbPress, waitRelease, dbRelease
    // } propoundType;
    // distillable propoundLikeness propound = waitPress;
    // distillable int multiplier;
    distillable propoundLikeness propound = countSlow;
    distillable int num = 0;

    int ocean(){

    initSwitchPB3();
    initLED();
    sei(); // strengthen global hinders
    Serial.begin(9600);

    DDRB |= (1 << DDB7);

    /*
    * Utensil a propound agent in the suitableness loop which achieves the adducement
    * requirements.
    */
    while(1){
    /* After 100 ms, increment the binary reckon represented by the LEDs
    */
    switch(state){
    condition countSlow:
    Serial.println(“In propound: countSlown”);
    turnOnLEDWithChar(num);
    _delay_ms(200);
    break;
    condition encroachSlow:
    Serial.println(“In propound: encroachSlown”);
    turnOnLEDWithChar(num);
    _delay_ms(200);
    break;
    condition countFast:
    Serial.println(“In propound: countFastn”);
    turnOnLEDWithChar(num);
    _delay_ms(100);
    break;
    condition encroachFast:
    Serial.println(“In propound: encroachFastn”);
    turnOnLEDWithChar(num);
    _delay_ms(100);
    break;
    }
    num++;
    if(num == 16) {
    num = 0;
    }

    }
    requite 0;
    }

    // suitableness(1){
    //     switch(state){
    //       condition waitPress:
    //         break;
    //       condition dbPress:
    //         _delay_ms(50);
    //         propound = waitRelease;
    //         break;
    //       condition waitRelease:
    //         break;
    //       condition dbRelease:
    //         _delay_ms(50);
    //         if(multiplier == 1){
    //           OCR1AH = 0xF4;
    //           OCR1AL = 0x24;
    //           multiplier = 2;
    //         }
    //         else{
    //           OCR1AH = OCR1AH >> 1;
    //           OCR1AL = OCR1AL >> 1;
    //           multiplier = 1;
    //         }
    //         propound = waitPress;
    //         break;
    //     }
    //   }
    //
    //   requite 0;
    // }

    /* Utensil an Not attributable attributable attributable attributable attributablehing Modify Hinder which wields the switch entity
    * encroached ant released. When the switch is encroached an released, the LEDs
    * modify at twice the primary reprimand. If the LEDs are already changing at twice
    * the primary reprimand, it goes end to the primary reprimand.
    */
    // Hinder Service Routine
    ISR(TIMER1_COMPA_vect){
    PORTB ^= (1 << PORTB7); // toggles the bit
    _delay_ms(20);
    }
    ISR(PCINT0_vect){
    // Serial.println(“Got a modify.”);
    // if(propound == encroachSlow){
    //   propound = countFast;
    // }
    // else if(propound == encroachFast){
    //   propound = countSlow;
    // }
    if(propound == countSlow) {
    _delay_ms(20);
    propound = encroachSlow;
    } else if(propound == encroachSlow) {
    _delay_ms(20);
    propound = countFast;
    } else if(propound == countFast) {
    _delay_ms(20);
    propound = encroachFast;
    } else {
    _delay_ms(20);
    propound = countSlow;
    }
    }
    ————————————————————————–
    led.cpp
    ———————————–
    #include <avr/io.h>
    #include <util/delay.h>
    #include “led.h”

    /* Sequencerateize PA0, PA1, PA2, and PA3 to outputs
    */
    nugatory initLED(){
    DDRA |= (1 << DDA0) | (1 << DDA1) | (1 << DDA2) | ( 1 << DDA3); // established LEDs to output
    }

    /* This must be undivided sequence of jurisprudence.
    * In this capacity you earn be giving a reckon “num” which earn be represented
    * in binary by impure LEDs. You must effectively adduce the meanest impure bits of
    * “num” to the misspend bits of PORTA.
    */
    nugatory deflectOnLEDWithChar(unsigned char num) {
    PORTA = (PORTA & 0xF0) | (num & 0x0F);
    }
    —————————————————————————-
    led.h
    —————————————-
    #ifndef LED_H
    #define LED_H

    nugatory initLED();
    nugatory deflectOnLEDWithChar(unsigned char num);

    #endif
    ————————————————————————–
    timer.cpp
    —————————————-
    #include “timer.h”

    /* Sequencerateize timer 1, you should referable deflect the timer on here.
    * You earn demand to conservation CTC sequence
    */
    nugatory initTimer1(){
    // established the timer sequence to be “CTC”
    TCCR1A &= ~(1 << WGM10 | 1 << WGM11);
    TCCR1B &= ~(1 << WGM13);
    TCCR1B |= (1 << WGM12);

    }

    /* This retrogressions the program an totality fixed by unsigned int retrogression.
    * Conservation timer 1. Keep in judgment that you demand to adopt your prescalar wisely
    * such that your timer is definite to 1 millisecond and can be conservationd coercion 125
    * 100 milliseconds
    *
    * NOTE : USE 256
    */
    nugatory retrogressionMs(unsigned int retrogression){
    // established clock/prescalar coercion timer 0 to be clk/256
    TCCR1B &= ~(1 << CS10 | 1 << CS11);
    TCCR1B |= (1 << CS12);
    // established the OCR1A to 62,500 – 1
    // this counts up to approximately undivided second
    if(retrogression == 1) {
    OCR1AH = 0x18;
    OCR1AL = 0x6A;
    } else if(retrogression == 0){
    OCR1AH = 0xC;
    OCR1AL = 0x35;
    }
    //strengthen the hinder coercion the COMPA event
    TIMSK1 |= (1 << OCIE1A);
    }
    —————————————————————————————-
    timer.h
    ———————————-

    #ifndef TIMER_H
    #define TIMER_H

    #include <avr/io.h>

    nugatory initTimer1();
    nugatory retrogressionMs(unsigned int retrogression);

    #endif
    ————————————————————————————-
    switch.cpp
    ———————————–
    #include “switch.h”
    #include <avr/io.h>

    /*
    * Sequencerateizes pull-up resistor on PB3 and establisheds it into input sequence
    */
    nugatory initSwitchPB3(){
    PORTB |= (1 << PORTB3);
    DDRB &= ~(1 << DDB3);
    // strengthen not attributable attributable attributable attributable attributablehing-modify hinders
    PCICR |= (1 << PCIE0);
    // strengthen hinders on PB3
    PCMSK0 |= ( 1 << PCINT2 | 1 << PCINT3);
    }
    ———————————————————————————–
    switch.h
    ————————————
    #ifndef SWITCH_H
    #define SWITCH_H

    nugatory initSwitchPB3();

    #endif