Scan to open on your phone
Point a camera at the QR code - it opens this exact paste, no app needed.
https://codepastes.com/zzgt2rn6ybnftpx5untitledPlain Text
// Pin numbers are defined by the corresponding LED colors
#define YELLOW_PIN 10
// The delay amounts are declared in ms; 1 s = 1000 ms
int red_on = 2000;
// Declaring the timer function to count 1 ms of delay instead of calling the delay function
int delay_timer (int milliseconds){
int count = 0;
while(1)
{
if(TCNT0 >= 15) // Checking if 1 millisecond has passed
{
The number of counts
needed to reach 1 ms =
(1,000 μs/64 μs) – 1 =
15.625 -1 ≈ 15. Experiment 2 Lab Manual
© Dept. of EEE, Faculty of Engineering, American International University-Bangladesh (AIUB) 3
TCNT0=0;
count++;
if (count == milliseconds) //checking if required milliseconds delay has passed
{
count=0;
break; // exits the loop
}
}
}
return 0;
}
void setup() {
//define pins connected to LEDs as outputs
pinMode(RED_PIN, OUTPUT);
//set up the timer using timer registers
TCCR0A = 0b00000000;
TCCR0B = 0b00000101; //setting pre-scaler for timer clock
TCNT0 = 0;
}
void loop() {
//to make the red LED turned on
digitalWrite(RED_PIN, HIGH);
delay_timer(red_on);
//turning off the red LED
digitalWrite(RED_PIN, LOW);
delay_timer(red_on);
}
1,152 chars · codepastes.com