/*
 * File:   ADC.c
 * Author: younn
 *
 * Created on October 30, 2024, 1:16 PM
 */

#include "xc.h"
#include "ADC.h"

void ADC_init(void) {
    AD1PCFGbits.PCFG5 = 0;
    AD1CON1 = 0x0000;
    AD1CON1bits.FORM = 0b00;
    AD1CON1bits.SSRC = 0b111;
    AD1CON1bits.ASAM = 0;
    AD1CON2 = 0x0000;
    AD1CON3 = 0x0000;
    AD1CON3bits.ADRC = 0;
    AD1CON3bits.SAMC = 31;
    AD1CON3bits.ADCS = 2;
    AD1CHS = 0x0005;
    AD1CSSL = 0x0000;
}

uint16_t do_ADC(void) {
    AD1CON1bits.ADON = 1;
    AD1CON1bits.SAMP = 1;
    AD1CON1bits.SAMP = 0;
    while(!AD1CON1bits.DONE);
    uint16_t result = ADC1BUF0;
    AD1CON1bits.ADON = 0;
    return result;
}




/*
 * File:   clkChange.c
 * Author: younn
 *
 * Created on October 3, 2024, 9:56 PM
 */

#include "clkChange.h"



void newClk(unsigned int clkval) {
    uint8_t COSCNOSC;
    switch(clkval) {
        case 8: // 8 MHz
            COSCNOSC = 0x00;
            break;
        case 500: // 500 kHz
            COSCNOSC = 0x66;
            break;
        case 32: // 32 kHz
            COSCNOSC = 0x55;
            break;
        default:
            COSCNOSC = 0x55;
    }
    SRbits.IPL = 7;
    CLKDIVbits.RCDIV = 0;
    __builtin_write_OSCCONH(COSCNOSC);
    __builtin_write_OSCCONL(0x01);
    while(OSCCONbits.OSWEN==1) {}
    SRbits.IPL = 0;
}




/*
 * File:   IOs.c
 * Author: younn
 *
 * Created on October 30, 2024, 1:15 PM
 */

#include <xc.h>
#include <stdint.h>
#include "UART2.h"
#include "ADC.h"
#include "IOs.h"
#include "timeDelay.h"

volatile uint8_t mode = 0;
volatile uint8_t pb1_pressed = 0;

void setup_IO(void) {
    TRISAbits.TRISA2 = 1;           // Configure RA2 as input.

    CNPU2bits.CN30PUE = 1;          // Enable pull-up resistor on CN30
    CNEN2bits.CN30IE = 1;           // Enable CN interrupt on CN30

    IPC4bits.CNIP = 6;              // Set CN interrupt priority to 6
    IFS1bits.CNIF = 0;              // Clear CN interrupt flag
    IEC1bits.CNIE = 1;              // Enable CN interrupts

    InitUART2();
    ADC_init();
}

void process_button(void) {
    if (pb1_pressed) {
        // Start debounce timer
        InitTimer2(20);

        // Wait for timer to finish
        while (!timer2_flag);
        timer2_flag = 0;

        // Check if button is still pressed
        if (!PORTAbits.RA2) {
            // Wait for button release
            while (!PORTAbits.RA2);

            // Toggle mode
            mode = !mode;
            if (mode == 0) {
                Disp2String("\rMode 0: Bar Graph Mode             ");
            } else {
                Disp2String("\rMode 1: Data Stream Mode           ");
            }
        }

        pb1_pressed = 0;
    }
}

void display_bargraph(uint16_t adc_value) {
    uint8_t bar_length = (adc_value * 32) / 1023;
    
    // Add carriage return to return to the beginning of the line
    Disp2String("\rMode 0: ");
    
    for (uint8_t i = 0; i < 32; i++) {
        XmitUART2((i < bar_length) ? '*' : ' ', 1);
    }
    
    Disp2String(" 0x");
    Disp2Hex(adc_value);
}

void send_adc_value(uint16_t adc_value) {
    Disp2Dec(adc_value);        // Send ADC value in decimal format
    XmitUART2('\n', 1);         // New line
}

void __attribute__((interrupt, no_auto_psv)) _CNInterrupt(void) {
    if (!PORTAbits.RA2) {
        pb1_pressed = 1;
        // Optional: Disable CN interrupt temporarily
        IEC1bits.CNIE = 0; // Disable CN interrupts
        Disp2String("\rCN interrupt triggered!\r");
    }

    IFS1bits.CNIF = 0; // Clear the interrupt flag

    IEC1bits.CNIE = 1; // Re-enable CN interrupts (if you disabled them)
}




/*
 * File:   main.c
 * Author: Younnus Iman, Taiwu Chen, Farha Ahmed
 *
 * Created on October 30, 2024, 9:54 PM
 */
// FBS
#pragma config BWRP = OFF               // Table Write Protect Boot (Boot segment may be written)
#pragma config BSS = OFF                // Boot segment Protect (No boot program Flash segment)

// FGS
#pragma config GWRP = OFF               // General Segment Code Flash Write Protection bit (General segment may be written)
#pragma config GCP = OFF                // General Segment Code Flash Code Protection bit (No protection)

// FOSCSEL
#pragma config FNOSC = FRC              // Oscillator Select (Fast RC oscillator (FRC))
#pragma config IESO = OFF               // Internal External Switch Over bit (Internal External Switchover mode disabled (Two-Speed Start-up disabled))

// FOSC
#pragma config POSCMOD = NONE           // Primary Oscillator Configuration bits (Primary oscillator disabled)
#pragma config OSCIOFNC = ON            // CLKO Enable Configuration bit (CLKO output disabled; pin functions as port I/O)
#pragma config POSCFREQ = HS            // Primary Oscillator Frequency Range Configuration bits (Primary oscillator/external clock input frequency greater than 8 MHz)
#pragma config SOSCSEL = SOSCHP         // SOSC Power Selection Configuration bits (Secondary oscillator configured for high-power operation)
#pragma config FCKSM = CSECMD           // Clock Switching and Monitor Selection (Clock switching is enabled, Fail-Safe Clock Monitor is disabled)

// FWDT
#pragma config WDTPS = PS32768          // Watchdog Timer Postscale Select bits (1:32,768)
#pragma config FWPSA = PR128            // WDT Prescaler (WDT prescaler ratio of 1:128)
#pragma config WINDIS = OFF             // Windowed Watchdog Timer Disable bit (Standard WDT selected; windowed WDT disabled)
#pragma config FWDTEN = OFF             // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))

// FPOR
#pragma config BOREN = BOR3             // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware; SBOREN bit disabled)
#pragma config PWRTEN = ON              // Power-up Timer Enable bit (PWRT enabled)
#pragma config I2C1SEL = PRI            // Alternate I2C1 Pin Mapping bit (Default location for SCL1/SDA1 pins)
#pragma config BORV = V18               // Brown-out Reset Voltage bits (Brown-out Reset set to lowest voltage (1.8V))
#pragma config MCLRE = ON               // MCLR Pin Enable bit (MCLR pin enabled; RA5 input pin disabled)

// FICD
#pragma config ICS = PGx2               // ICD Pin Placement Select bits (PGC2/PGD2 are used for programming and debugging the device)

// FDS
#pragma config DSWDTPS = DSWDTPSF       // Deep Sleep Watchdog Timer Postscale Select bits (1:2,147,483,648 (25.7 Days))
#pragma config DSWDTOSC = LPRC          // DSWDT Reference Clock Select bit (DSWDT uses LPRC as reference clock)
#pragma config RTCOSC = SOSC            // RTCC Reference Clock Select bit (RTCC uses SOSC as reference clock)
#pragma config DSBOREN = ON             // Deep Sleep Zero-Power BOR Enable bit (Deep Sleep BOR enabled in Deep Sleep)
#pragma config DSWDTEN = ON             // Deep Sleep Watchdog Timer Enable bit (DSWDT enabled)

// #pragma config statements should precede project file includes.

#include "xc.h"
#include "ADC.h"
#include "IOs.h"
#include "clkChange.h"
#include "timeDelay.h"
#include "UART2.h"

int main(void) {
    newClk(500);
    AD1PCFG = 0xFFFF;
    setup_IO();
    InitTimer2(100);  // 100 ms delay
    uint16_t last_adc_value = 0;

    while(1) {
        Idle();

        process_button();  // Check the button at the start of each loop

        if(timer2_flag) {
            timer2_flag = 0;  // Reset the timer flag
            
            uint16_t adc_value = do_ADC();

            if(mode == 0) {
                // Mode 0: Update display only if the ADC value changed significantly
                if ((adc_value > last_adc_value && adc_value - last_adc_value > 10) || 
                    (adc_value < last_adc_value && last_adc_value - adc_value > 10)) {
                    display_bargraph(adc_value);
                    last_adc_value = adc_value; 
                }
            } else {
                // Mode 1: Always send ADC value
                send_adc_value(adc_value);
            }

            // Restart the timer for the next loop
            InitTimer2(100);
        }
    }

    return 0;
}





/*
 * File:   timeDelay.c
 * Author: younn
 *
 * Created on October 3, 2024, 10:19 PM
 */

#include "xc.h"
#include "timeDelay.h"

volatile uint8_t timer2_flag = 0;

void InitTimer2(uint16_t delay_ms) {
    T2CONbits.TCKPS = 0b10;       // 1:64 prescaler
    PR2 = (250 * delay_ms) / 64;  // Calculate PR2 for delay in ms at 500 kHz
    TMR2 = 0;
    IFS0bits.T2IF = 0;
    IEC0bits.T2IE = 1;
    T2CONbits.TON = 1;
}

void __attribute__((interrupt, no_auto_psv)) _T2Interrupt(void) {
    IFS0bits.T2IF = 0;
    timer2_flag = 1;
    T2CONbits.TON = 0;
}





/*
 * File:   UART2.c
 * Author: younn
 *
 * Created on October 3, 2024, 9:55 PM
 */


#include "xc.h"
#include "math.h"
#include "string.h"

#include "UART2.h"




unsigned int clkval;

///// Initialization of UART 2 module.

void InitUART2(void) 
{
	// configures UART2 module on pins RB0 (Tx) and RB1 (Rx) on PIC24F16KA101 
	// Enables UART2 
	//Set to Baud 4800 with 500kHz clk on PIC24F
	
	TRISBbits.TRISB0=0;
	TRISBbits.TRISB1=1;
	LATBbits.LATB0=1;

	// configure U2MODE
    U2MODE = 0b0000000000001000;
/*    
	U2MODEbits.UARTEN = 0;	// Bit15 TX, RX DISABLED, ENABLE at end of func
	U2MODEbits.USIDL = 0;	// Bit13 Continue in Idle
	U2MODEbits.IREN = 0;	// Bit12 No IR translation
	U2MODEbits.RTSMD = 0;	// Bit11 Simplex Mode
	U2MODEbits.UEN = 0;		// Bits8,9 TX,RX enabled, CTS,RTS not
	U2MODEbits.WAKE = 0;	// Bit7 No Wake up (since we don't sleep here)
	U2MODEbits.LPBACK = 0;	// Bit6 No Loop Back
	U2MODEbits.ABAUD = 0;	// Bit5 No Autobaud (would require sending '55')
	U2MODEbits.RXINV = 0;	// Bit4 IdleState = 1
	U2MODEbits.BRGH = 1;	// Bit3 16 clocks per bit period
	U2MODEbits.PDSEL = 0;	// Bits1,2 8bit, No Parity
	U2MODEbits.STSEL = 0;	// Bit0 One Stop Bit
 */
	if (OSCCONbits.COSC == 0b110)
	{
		U2BRG = 12;	// gives a baud rate of 4807.7 Baud with 500kHz clock; Set Baud to 4800 on realterm
	}
	else if (OSCCONbits.COSC == 0b101)
	{
		U2BRG = 12;	// gives a baud rate of 300 Baud with 32kHz clock; set Baud to 300 on realterm
	}
	else if (OSCCONbits.COSC == 0b000)
	{
		U2BRG=103;	// gives a baud rate of 9600 with 8MHz clock; set Baud to 9600 on real term
	}
	// Load all values in for U1STA SFR
	U2STA = 0b1010000000000000;
    /*
    U2STAbits.UTXISEL1 = 1;	//Bit15 Int when Char is transferred (1/2 config!)
    U2STAbits.UTXISEL0 = 1;	//Generate interrupt with last character shifted out of U2TXREG buffer
	U2STAbits.UTXINV = 0;	//Bit14 N/A, IRDA config
	U2STAbits.UTXBRK = 0;	//Bit11 Disabled
	U2STAbits.UTXEN = 0;	//Bit10 TX pins controlled by periph
	U2STAbits.UTXBF = 0;	//Bit9 *Read Only Bit*
	U2STAbits.TRMT = 0;		//Bit8 *Read Only bit*
	U2STAbits.URXISEL = 0;	//Bits6,7 Int. on character recieved
	U2STAbits.ADDEN = 0;	//Bit5 Address Detect Disabled
	U2STAbits.RIDLE = 0;	//Bit4 *Read Only Bit*
	U2STAbits.PERR = 0;		//Bit3 *Read Only Bit*
	U2STAbits.FERR = 0;		//Bit2 *Read Only Bit*
	U2STAbits.OERR = 0;		//Bit1 *Read Only Bit*
	U2STAbits.URXDA = 0;	//Bit0 *Read Only Bit*
    */
	IFS1bits.U2TXIF = 0;	// Clear the Transmit Interrupt Flag
    IPC7bits.U2TXIP = 3; // UART2 TX interrupt has interrupt priority 3-4th highest priority
    
	IEC1bits.U2TXIE = 1;	// Enable Transmit Interrupts
	IFS1bits.U2RXIF = 0;	// Clear the Recieve Interrupt Flag
	IPC7bits.U2RXIP = 4; //UART2 Rx interrupt has 2nd highest priority
    IEC1bits.U2RXIE = 0;	// Disable Recieve Interrupts

	U2MODEbits.UARTEN = 1;	// And turn the peripheral on

	U2STAbits.UTXEN = 1;
	return;
}



///// XmitUART2: 
///// Displays 'DispData' on realterm 'repeatNo' of times using UART to PC. 
///// Adjust Baud on real term as per clock: 32kHz clock - Baud=300 // 500kHz clock - Baud=4800 

void XmitUART2(char CharNum, unsigned int repeatNo)
{	
	
	InitUART2();	//Initialize UART2 module and turn it on
	while(repeatNo!=0) 
	{
		while(U2STAbits.UTXBF==1)	//Just loop here till the FIFO buffers have room for one more entry
		{
			// Idle();  //commented to try out serialplot app
		}	
		U2TXREG=CharNum;	//Move Data to be displayed in UART FIFO buffer
		repeatNo--;
	}
	while(U2STAbits.TRMT==0)	//Turn off UART2 upon transmission of last character; also can be Verified in interrupt subroutine U2TXInterrupt()
	{
		//Idle();
	}
	U2MODEbits.UARTEN = 0;	
	return;
}


void __attribute__ ((interrupt, no_auto_psv)) _U2RXInterrupt(void) {
//	LATA = U2RXREG;
	IFS1bits.U2RXIF = 0;
}
void __attribute__ ((interrupt, no_auto_psv)) _U2TXInterrupt(void) {
	IFS1bits.U2TXIF = 0;

}




// Displays 16 bit number in Hex form using UART2
void Disp2Hex(unsigned int DispData)   
{
    char i;
    char nib = 0x00;
    XmitUART2(' ',1);  // Disp Gap
    XmitUART2('0',1);  // Disp Hex notation 0x
    XmitUART2('x',1);
    
    for (i=3; i>=0; i--)
    {
        nib = ((DispData >> (4*i)) & 0x000F);
        if (nib >= 0x0A)
        {
            nib = nib +0x37;  //For Hex values A-F
        }
        else 
        {
            nib = nib+0x30;  //For hex values 0-9
        }
        XmitUART2(nib,1);
    }
    
    XmitUART2(' ',1);
    DispData = 0x0000;  // Clear DispData
    return;
}


void Disp2Hex32(unsigned long int DispData32)   // Displays 32 bit number in Hex form using UART2
{
    char i;
    char nib = 0x00;
    XmitUART2(' ',1);  // Disp Gap
    XmitUART2('0',1);  // Disp Hex notation 0x
    XmitUART2('x',1);
    
    for (i=7; i>=0; i--)
    {
        nib = ((DispData32 >> (4*i)) & 0x000F);
        if (nib >= 0x0A)
        {
            nib = nib +0x37;  //For Hex values A-F
        }
        else 
        {
            nib = nib+0x30;  //For hex values 0-9
        }
        XmitUART2(nib,1);
    }
    
    XmitUART2(' ',1);
    DispData32 = 0x00000000;  // Clear DispData
    return;
}

// Displays 16 bit unsigned in in decimal form
void Disp2Dec(uint16_t Dec_num)
{
    uint8_t rem;  //remainder in div by 10
    uint16_t quot; 
    uint8_t ctr = 0;  //counter
    XmitUART2(' ',1);  // Disp Gap
    while(ctr<5)
    {
        quot = Dec_num/(pow(10,(4-ctr)));
        rem = quot%10;
        XmitUART2(rem + 0x30 , 1);
        ctr = ctr + 1;
    }
    XmitUART2(' ',1);  // Disp Gap
    // XmitUART2('\n',1);  // new line
    // XmitUART2('\r',1);  // carriage return
   
    return;
}


void Disp2String(char *str) //Displays String of characters
{
    unsigned int i;
   // XmitUART2(0x0A,2);  //LF
   // XmitUART2(0x0D,1);  //CR 
    for (i=0; i<= strlen(str); i++)
    {
          
        XmitUART2(str[i],1);
    }
    // XmitUART2(0x0A,2);  //LF
    // XmitUART2(0x0D,1);  //CR 
    
    return;
}



here is code for an older assignment now I have to do this:


App Project 2: LED Intensity Controller (Group Project)
Due Date: As per D2L Dropbox
Assignment: Using the Microcontroller and your experience from developing driver functions developed so far,
you will design an “LED Light Control” App to control the brightness/ intensity of an LED connected to pin 12.
You will also log the brightness setting on your PC with a Python program that you must design and implement.
The requirements that your project must satisfy are described in this brief. The push buttons are defined as in
the previous assignments and should be connected to the same pins as before. We define a push button “click”
as a press and release of a button.
User input(s) Output(s)
If PB1 is clicked (i.e.,
there should be no need
to “hold down” the
button)
After programming the microcontroller, if PB1 is clicked, it should put the System
in ON MODE. In this mode, the LED should turn on. Turning the potentiometer
should adjust the LED intensity to between full brightness and 0% (LED off).
The variable brightness must be achieved by using Pulse width modulation of the
signal supplied to the LED as described below.
If PB1 is pressed again, the System should enter OFF mode, i.e., turn off the LED
and put the system in low-power Idle() mode.
If PB2 is clicked (i.e.,
there should be no need
to “hold down” the
button)
While in ON MODE, if PB2 is pressed once, it should blink the LED. When the LED
is on during the blink, it should be at the intensity level corresponding to the
current ADC reading. When the LED is off during the blink, the intensity is 0. The
blinking should happen at approx. 500 ms intervals (0.5 s on, 0.5 s off). If you turn
the potentiometer, the intensity while blinking should adjust accordingly.
While in OFF MODE, if PB2 is pressed once, it should blink the LED at 100%
intensity level at approx. 500 ms intervals (0.5 s on, 0.5 s off).
The LED blinking should stop if PB2 is clicked again in either mode.
If PB3 is clicked (i.e.,
there should be no need
to “hold down” the
button)
If PB3 is clicked during the ON MODE (non-blink) or ON MODE (blink), the
microcontroller should start to transmit the intensity level and ADC reading to a
PC over UART. On the PC, you should design and implement a Python script to
receive the UART transmissions. For a period of 1 minute:
1. Capture and Store the intensity levels (0-100%) of the LED and the ADC
readings from the microcontroller, in a single CSV file with appropriate
indexing and column names. You should time-stamp the readings
appropriately.
2. After 1 minute, you should produce a graph/plot of the intensity levels
(0-100%) vs. time (in seconds) and another graph of the ADC reading vs.
time (i.e., two separate graphs, that could be subplots).
Your graphs must have an appropriate title and axes labels. The generated CSV
file should be named as per your group name and have proper index numbers
and column names. In order to capture the LED blinking properly, you will need
to transmit data at a rate of more than 2 Hz. Note that while the LED is off
(during a blink), we would expect the “intensity” readings to be 0%.
ALL SECTIONS: Version 1
ENSF 460, Fall 2024 | R. Vyas / B. Tan
Clicking PB3 again, or leaving the ON MODE, should stop the UART transmissions.
While transmitting, it must be possible for a user to go back and forth between
blink and non-blink modes and have the transmitted data/generate graph show
the transition. Note that UART transmissions should only occur after PB3 has
been clicked as described above.
Additional info:
Implement the above controller in C as a finite-state machine-based controller, to run on your hardware kit. You
must not use the Output Compare/PWM peripheral in this project. Polling of PORTx or TMRx directly, or
corresponding flags that you create, instead of interrupt-driven programming, may lose points. Note that you
may use multiple timer peripherals or the 32-bit timer configuration at your discretion. You might recall that
there are three timers available to you. You will need to navigate the datasheet by yourselves, accordingly.
Your implementation should be as power-efficient as possible. You may implement “polling-like” behavior to
read your ADC and determine when to send data over UART.
Function names: You may use any convention when naming functions or organizing code. A state diagram of
your design is required as part of your submission. Use microcontroller-specific registers, bit names, and flags (to
jump between states) wherever applicable in the state diagram. Your C code must accurately reflect your FSM
and vice versa.
Display instructions: All displays on the PC should be using Python. Note that display functions carried out at 32
kHz (300 Baud) can affect timer delays. Your code should account for such delays when producing delays
specified in the table above. You may choose to use whatever clock speed(s) available to you as you see fit.
Interrupts: Interrupt ISR names are provided in the lecture slides. As specified in lectures, IO (CN interrupts) are
triggered on rising and falling edges and due to any bounce effects of the push buttons that cause several high-
to-low and low-to-high fluctuations at the Microcontroller input. Your code should filter out any such effects.
Note: the “click” behavior descriptions above suggest that your system must not change state just because a
button is pressed (so a press and hold down should not cause a behavior change), but the button being released
should.
Your submission must satisfy the following in addition to achieving all requirements of this project and
delivering all deliverables to gain full marks: (i) You do not call functions in an ISR (this includes no UART
messages in the ISR), unless you can prove that the function(s) called are reentrant (ii) You do not have infinite
loops in an ISR, (iii) You do not add delays to the ISR, (iv) You do not poll the input ports (i.e., your program
should not be repeatedly testing (reading) the value of the PORTA or PORTB, (v) Your submission should not
have “glitches” (e.g., pushing the buttons in an arbitrary order at arbitrary times should not result in unexpected
behavior), (vi) your C program does not poll status flags related to the timers or inputs, and (vii) there should not
be any visual flickering of the LED. You may submit a project that does not satisfy all requirements but will only
receive partial credit. All members of your group must be in attendance at the demo.
You are responsible for regularly checking D2L for announcements (e.g., via the News tool) regarding the
project. As with any engineering project, requirements and guidance are subject to change at the teaching
team’s discretion. If you require clarification, it is your responsibility to discuss your thoughts with the instructor
during the timetabled class times.
ALL SECTIONS: Version 1
ENSF 460, Fall 2024 | R. Vyas / B. Tan
Pulse Width Modulated Signals (PWM):
PWM signals are commonly used in many mechatronic applications like light and motor control, etc., and look
like Figures 1 and 2 below. You will program the microcontroller to generate a PWM signal from Pin 12,
connected to an LED via a 1K-ohm current limiting resistor. The duty cycle should be controllable based on the
Potentiometer input.
(Figure Sources: realdigital.org)
Figure 1: Relationship between PWM Duty cycle and LED brightness or intensity levels
Vpwm = Duty Cycle/100 * VDD, where
Vpwm: PWM voltage or average voltage of a PWM Signal
VDD: Voltage supplied on a Microcontroller pin
Figure 2: PWM Signal
Pulse Frequency: You can use any pulse frequency for your app. However, the pulse frequency should be high
enough so that the resulting LED flicker is not visible to the human eye but, at the same time, not too high to
consume excessive power. Use trial and error when coding your app to determine an appropriate Pulse
Frequency.


few things that you need to know

    TRISBbits.TRISB8 = 0;  // LED as output
    
    TRISAbits.TRISA2 = 1;  // PB1 as input
    TRISBbits.TRISB4 = 1;  // PB2 as input
    TRISAbits.TRISA4 = 1;  // PB3 as input

right now the UART display keeps displaying the updates on new lines, despite whatever we do including using \r instead of \n, we want it to just update the line and not continue outputing multiple new lines, ideally by erasing the previous output and inputing the new one over it or perhaps something else if possible. We also need a python file as specified by the assignment, please show me the code that would change according to this assignment