Question

In: Computer Science

Make a C program to blink/toggle a LED every second with the Atmega128 chip. Hint: Because...

Make a C program to blink/toggle a LED every second with the Atmega128 chip.
Hint: Because the delay function has a maximum delay limit, you will need an internal counter to accumulate delays to one second.

a) Write code that uses the delay function for implementation

b) Write code that uses a stopwatch on the third toggle

Solutions

Expert Solution

a) Write code that uses the delay function for implementation

// C progam to impliment delay function

// you can use it for time delay


#include <stdio.h>

#include <time.h> // To use time library of C

void delay(int number_of_seconds)
{
   // Converting time into milli_seconds 1000 milli seconds=1 seconds
   int milli_seconds = 1000 * number_of_seconds;

   // Storing start time
   clock_t start_time = clock();

   // looping till required time is not achieved
   while (clock() < start_time + milli_seconds)
       ;
}

// Driver code to test the function
int main()
{
   int i;
   for (i = 0; i < 10; i++) {
       // delay of one second
       delay(1);
       printf("%d seconds have passed\n", i + 1);
   }
   return 0;
}

b) Write code that uses a stopwatch on the third toggle

# Python program to impliment a stop watch
#importing the required libraries


import tkinter as Tkinter
from datetime import datetime
counter = 66600
running = False
def counter_label(label):
   def count():
       if running:
           global counter
  
           # To manage the intial delay.
           if counter==66600:             
               display="Starting..."
           else:
               tt = datetime.fromtimestamp(counter)
               string = tt.strftime("%H:%M:%S")
               display=string
  
           label['text']=display # Or label.config(text=display)
  
           # label.after(arg1, arg2) delays by
           # first argument given in milliseconds
           # and then calls the function given as second argument.
           # Generally like here we need to call the
           # function in which it is present repeatedly.
           # Delays by 1000ms=1 seconds and call count again.
           label.after(1000, count)
           counter += 1
  
   # Triggering the start of the counter.
   count()     
  
# start function of the stopwatch
def Start(label):
   global running
   running=True
   counter_label(label)
   start['state']='disabled'
   stop['state']='normal'
   reset['state']='normal'
  
# Stop function of the stopwatch
def Stop():
   global running
   start['state']='normal'
   stop['state']='disabled'
   reset['state']='normal'
   running = False
  
# Reset function of the stopwatch
def Reset(label):
   global counter
   counter=66600
  
   # If rest is pressed after pressing stop.
   if running==False:     
       reset['state']='disabled'
       label['text']='Welcome!'
  
   # If reset is pressed while the stopwatch is running.
   else:                 
       label['text']='Starting...'
  
root = Tkinter.Tk()
root.title("Stopwatch")
  
# Fixing the window size.
root.minsize(width=250, height=70)
label = Tkinter.Label(root, text="Welcome!", fg="black", font="Verdana 30 bold")
label.pack()
f = Tkinter.Frame(root)
start = Tkinter.Button(f, text='Start', width=6, command=lambda:Start(label))
stop = Tkinter.Button(f, text='Stop',width=6,state='disabled', command=Stop)
reset = Tkinter.Button(f, text='Reset',width=6, state='disabled', command=lambda:Reset(label))
f.pack(anchor = 'center',pady=5)
start.pack(side="left")
stop.pack(side ="left")
reset.pack(side="left")
root.mainloop()


Related Solutions

Make a C program to blink/toggle a LED every second with the Atmega128 chip. Hint: Because...
Make a C program to blink/toggle a LED every second with the Atmega128 chip. Hint: Because the delay function has a maximum delay limit, you will need an internal counter to accumulate delays to one second. a) Write code that uses the timer interrupt for implementation. b) Write code that uses stopwatch on the second toggle in Atmel Studio
1.write a program for the msp430 to make led 1 blink at 50 percent duty cycle....
1.write a program for the msp430 to make led 1 blink at 50 percent duty cycle. 2 modify the program to make led 1 blink 5 times, make a long pause, then blink 5 more times then stop. The time delays should be carried out in subroutines
1.write a program for the msp430FR6989 to make led 1 blink at 50 percent duty cycle....
1.write a program for the msp430FR6989 to make led 1 blink at 50 percent duty cycle. 2 modify the program to make led 1 blink 5 times, make a long pause, then blink 5 more times then stop. The time delays should be carried out in subroutines
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and...
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and the green LED at the same time. The two LEDs should be on at the same time and then off at the same time
Write a C program to blink two LEDs connected to Raspberry pi. One must blink at...
Write a C program to blink two LEDs connected to Raspberry pi. One must blink at a rate of 1 Hz and the other at a rate of 2 HZ.
For the mspfr6989 write program #2 1(b) Write a program that will make LED1 blink 5...
For the mspfr6989 write program #2 1(b) Write a program that will make LED1 blink 5 times when S1 is pressed, and then stop. Program #2 – Using both S1 and S2 1 Write a program like 1(b) above, but the LED1 will blink until S2 is pressed. 2 Write a program that simulates a motor coming up to speed. When S1 is pressed, LED1 blinks at 50% duty cycle for 10 cycles (indicating a motor coming up to speed)....
Write the following in C language for Arduino: Write a program that turns on the LED...
Write the following in C language for Arduino: Write a program that turns on the LED at 25%, 50%, 75%, 100%, and then 0% brightness with a one second delay in between each change. Remember you are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine the values for...
Write a program in C that allows you to determine the endianness of your computer. Hint:...
Write a program in C that allows you to determine the endianness of your computer. Hint: use unsigned char* ptr. Your task is to explain this code. Make sure that you are detailed in your explanation by explaining the significant lines. In particular, correct explanation of lines 12, 13, 15, 18, 21, 22, 24, 25, 26 and 27 will earn 1 point each. Additionally, explain the overall purpose of the logical operations in lines 24-27 for 2 points. Your explanation...
Write the following in C language for Arduino: Write a program that increases the LED brightness...
Write the following in C language for Arduino: Write a program that increases the LED brightness in five steps with each press of the button. Remember you are going to using a digital input and the "digitalRead" command. You are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine...
Write a program for the msp430 to make led1 and led 2 alternate blinking 2. repeat...
Write a program for the msp430 to make led1 and led 2 alternate blinking 2. repeat the program to make each led blink 5 times in a sequence, then 5 times simultaneously
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT