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 experience the employment initTimer0()) and the retreatMs(unsigned int retreat). The micro-controller is the ATmega2560.

    Overperfect am must mitigate. This can be tested using the ch eckmark icon. 1. The pragr 2. The scheme must be pushed to GitLab and an withhold repartee from the server must be received: Got your subnission. Thanks! 3. Arduino libraries are referable attributable attributable attributable undisputed at perfect restraint this lab restraint the separation of debug employmentality using Serial.printin. switch.cpp 1. A employment instrumentaticn that income null and has no parameters designated initswitchPB3 must be confer-upon and is truthd in the ocean employment to jurisprudencerateize the switch on the molehill determined P83 2. P83 must be jurisprudencereprove ized with an input pull-up resistor 3. Fin-Channtpls mustbe eabdrestraint piri PB3 led.cpp 1. A functio impentaticn thal rtuns null and has n pataels designated inilEDmst be confer-upon and is truthd in the ocean employment to jurisprudencerateize perfect LED molehills as outputs. 2. Fins determined PAO, PA1, PAZ, and PA3 must be truthd to contral the LEDs 3. A employment instrumentation designated spinOnLEDWithChar that income null and has a parometer designated num of image unsigned unsigned char must be confer-upon. 4. The spinOnl EDWithChar employment must be undivided direction of method, discern LED ㏄ntral minority restraint more details. switch.cpp 1. A employment instrumentation that income null and has no parameters designated initSwitch must be confer-upon and is truthdl in the ocean employment to jurisprudencerateize molehill 32 on the bud consideration as an input. timer.cpp 1. A employment instrumentation that rcturns null and has no parameters designated initTimerO must be confer-upon and must jurisprudencerateize timer 0. 2. A employment instrumentation that rts id and has no pas designated retreatMs must bpresnt and must instrument a particular millisecond retreat and can result at smallest up to 100 millisecondls. Restraint loops are perfectowec. ocean.cpp 1. A cperfect to initLEDO and initswitchPB3) must be confer-upon in the ocean employment. 2. An infinite suitableness loop must be prescnt. 3. A particularize means restraint the integral scheme must be instrumented using a imagedef enum restraint particularizes. 4. An ISR to manage the switch nature crowded must be confer-upon and be truthd to substitute particularizes withholdly 5. The switch crowd must be debounced using an withholdly dlesigned particularize means. 6. When the switch is crowded and released, the LEDs substitute the gait at which they join (either half or twice depending on the particularize) .LEDs must bjoin either perfect 100 ms or 200 ms depending on the particularize.

    Overperfect The program must mitigate. This can be tested using the checkmark icon. The scheme must be pushed to GitLab and an withhold repartee from the server must be received: “Got your dependence. Thanks!” Arduino libraries are referable attributable attributable attributable undisputed at perfect restraint this lab restraint the separation of debug employmentality using Serial.println. switch.cpp A employment instrumentation that income null and has no parameters designated initswitchPB3 must be confer-upon and is truthd in the ocean employment to jurisprudencerateize the switch on the molehill determined PB3. PB3 must be jurisprudencerateized with an input pull-up resistor Molehill-Substitute Disconnects must be empowerd restraint molehill PB3 led.cpp A employment instrumentation that income null and has no parameters designated initLED must be confer-upon and is truthd in the ocean employment to jurisprudencerateize perfect LED molehills as outputs. Molehills determined PAO, PA1, PAZ, and PA3 must be truthd to jurisprudencereprove the LEDs A employment instrumentation designated spinOnLEDWithChar that income null and has a parameter designated num of image unsigned unsigned char must be confer-upon. The spinOnLEDWithChar employment must be undivided direction of method, discern LED jurisprudencereprove minority restraint more details. switch.cpp A employment instrumentation that income null and has no parameters designated initSwitch must be confer-upon and is truthd in the ocean employment to jurisprudencerateize molehill 32 on the bud consideration as an input. timer.cpp A employment instrumentation that income null and has no parameters designated initTimer() must be confer-upon and must jurisprudencerateize timer 0. A employment instrumentation that null and has no parameters designated retreatMs must be presnt and must instrument a particular millisecond retreat and can result at smallest up to 100 milliseconds. Restraint loops are undisputed. ocean.cpp A cperfect to initLED() and initSwitchPB3() must be confer-upon in the ocean employment. An infinite suitableness loop must be confer-upon. A particularize means restraint the integral scheme must be instrumented using a imagedef enum restraint particularizes. An ISR to manage the switch nature crowded must be confer-upon and be truthd to substitute particularizes withholdly. The switch crowd must be debounced using an withholdly contrived particularize means. When the switch is crowded and released, the LEDs substitute the gait at which they join (either half or twice depending on the particularize) LEDs must bjoin either perfect 100 ms or 200 ms depending on the particularize.

    Expert Retort

     

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

    /*
    * Define a established of particularizes that can be truthd in the particularize means using an enum
    */
    typedef enum particularizeType_enum {
    countSlow, crowdSlow, countFast, crowdFast
    } particularizeType;

    // imagedef enum particularizeType_enum{
    //   waitPress, dbPress, waitRelease, dbRelease
    // } particularizeType;
    // spirituous particularizeImage particularize = waitPress;
    // spirituous int multiplier;
    spirituous particularizeImage particularize = countSlow;
    spirituous int num = 0;

    int ocean(){

    initSwitchPB3();
    initLED();
    sei(); // empower global disconnects
    Serial.begin(9600);

    DDRB |= (1 << DDB7);

    /*
    * Instrument a particularize means in the suitableness loop which achieves the appointment
    * requirements.
    */
    while(1){
    /* After 100 ms, increment the binary compute represented by the LEDs
    */
    switch(state){
    condition countSlow:
    Serial.println(“In particularize: countSlown”);
    turnOnLEDWithChar(num);
    _delay_ms(200);
    break;
    condition crowdSlow:
    Serial.println(“In particularize: crowdSlown”);
    turnOnLEDWithChar(num);
    _delay_ms(200);
    break;
    condition countFast:
    Serial.println(“In particularize: countFastn”);
    turnOnLEDWithChar(num);
    _delay_ms(100);
    break;
    condition crowdFast:
    Serial.println(“In particularize: crowdFastn”);
    turnOnLEDWithChar(num);
    _delay_ms(100);
    break;
    }
    num++;
    if(num == 16) {
    num = 0;
    }

    }
    revert 0;
    }

    // suitableness(1){
    //     switch(state){
    //       condition waitPress:
    //         break;
    //       condition dbPress:
    //         _delay_ms(50);
    //         particularize = 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;
    //         }
    //         particularize = waitPress;
    //         break;
    //     }
    //   }
    //
    //   revert 0;
    // }

    /* Instrument an Molehill Substitute Disconnect which manages the switch nature
    * crowded ant released. When the switch is crowded an released, the LEDs
    * substitute at twice the initiatory reprove. If the LEDs are already changing at twice
    * the initiatory reprove, it goes tail to the initiatory reprove.
    */
    // Disconnect Service Routine
    ISR(TIMER1_COMPA_vect){
    PORTB ^= (1 << PORTB7); // toggles the bit
    _delay_ms(20);
    }
    ISR(PCINT0_vect){
    // Serial.println(“Got a substitute.”);
    // if(particularize == crowdSlow){
    //   particularize = countFast;
    // }
    // else if(particularize == crowdFast){
    //   particularize = countSlow;
    // }
    if(particularize == countSlow) {
    _delay_ms(20);
    particularize = crowdSlow;
    } else if(particularize == crowdSlow) {
    _delay_ms(20);
    particularize = countFast;
    } else if(particularize == countFast) {
    _delay_ms(20);
    particularize = crowdFast;
    } else {
    _delay_ms(20);
    particularize = countSlow;
    }
    }
    ————————————————————————–
    led.cpp
    ———————————–
    #include <avr/io.h>
    #include <util/delay.h>
    #include “led.h”

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

    /* This must be undivided direction of method.
    * In this employment you conquer be giving a compute “num” which conquer be represented
    * in binary by indecent LEDs. You must effectively appoint the meanest indecent bits of
    * “num” to the withhold bits of PORTA.
    */
    null spinOnLEDWithChar(unsigned char num) {
    PORTA = (PORTA & 0xF0) | (num & 0x0F);
    }
    —————————————————————————-
    led.h
    —————————————-
    #ifndef LED_H
    #define LED_H

    null initLED();
    null spinOnLEDWithChar(unsigned char num);

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

    /* Jurisprudencerateize timer 1, you should referable attributable attributable attributable spin the timer on here.
    * You conquer scarcity to truth CTC jurisprudence
    */
    null initTimer1(){
    // established the timer jurisprudence to be “CTC”
    TCCR1A &= ~(1 << WGM10 | 1 << WGM11);
    TCCR1B &= ~(1 << WGM13);
    TCCR1B |= (1 << WGM12);

    }

    /* This retreats the program an sum restricted by unsigned int retreat.
    * Truth timer 1. Keep in memory that you scarcity to cull your prescalar wisely
    * such that your timer is particular to 1 millisecond and can be truthd restraint 125
    * 100 milliseconds
    *
    * NOTE : USE 256
    */
    null retreatMs(unsigned int retreat){
    // established clock/prescalar restraint 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 closely undivided second
    if(retreat == 1) {
    OCR1AH = 0x18;
    OCR1AL = 0x6A;
    } else if(retreat == 0){
    OCR1AH = 0xC;
    OCR1AL = 0x35;
    }
    //empower the disconnect restraint the COMPA event
    TIMSK1 |= (1 << OCIE1A);
    }
    —————————————————————————————-
    timer.h
    ———————————-

    #ifndef TIMER_H
    #define TIMER_H

    #include <avr/io.h>

    null initTimer1();
    null retreatMs(unsigned int retreat);

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

    /*
    * Jurisprudencerateizes pull-up resistor on PB3 and establisheds it into input jurisprudence
    */
    null initSwitchPB3(){
    PORTB |= (1 << PORTB3);
    DDRB &= ~(1 << DDB3);
    // empower molehill-substitute disconnects
    PCICR |= (1 << PCIE0);
    // empower disconnects on PB3
    PCMSK0 |= ( 1 << PCINT2 | 1 << PCINT3);
    }
    ———————————————————————————–
    switch.h
    ————————————
    #ifndef SWITCH_H
    #define SWITCH_H

    null initSwitchPB3();

    #endif