<commit_before>#include <avr/interrupt.h>

volatile int timer_overflow_count = 0;

ISR(TIM0_OVF_vect) {
   if (++timer_overflow_count > 5) {   // a timer overflow occurs 4.6 times per second
      // Toggle Port B pin 4 output state
      PORTB ^= 1<<PB4;
      timer_overflow_count = 0;
   }
}

int main(void) {
   // Set up Port B pin 4 mode to output
    DDRB = 1<<DDB4;

   // prescale timer to 1/1024th the clock rate
   TCCR0B |= (1<<CS02) | (1<<CS00);

   // enable timer overflow interrupt
   TIMSK |=1<<TOIE0;
   sei();

   while(1) {
      // let ISR handle the LED forever
   }
}<commit_msg>simple traffic light application with no communication<commit_after>#include <avr/io.h>
#include <avr/interrupt.h>

volatile int timer_overflow_count = 0;

#define RED_PIN PB3
#define YELLOW_PIN PB4
#define GREEN_PIN PB5

/**
  The timing of a traffic light determines how the light_time is translated
  into light patterns. A and B timing are defined such that cars coming from
  A and B direction never have green light at the same time.
*/
typedef enum {A, B} LightTiming;
LightTiming timing = A;

/**
  light_time contains the global time which is shared by all traffic lights
  The correct state of the lights is computed from this.
  The unit is seconds.
*/
int light_time = 0;

/* define the schedule
*/
#define RED_TIME 35
#define YELLOW_RED_TIME 1
#define GREEN_TIME 18
#define YELLOW_TIME 4

// calculate the cycle time and the switch times based on this
#define CYCLE_TIME  (RED_TIME + YELLOW_RED_TIME + GREEN_TIME + YELLOW_TIME)
#define SWITCH_TO_YELLOW_RED_TIME (RED_TIME)
#define SWITCH_TO_GREEN_TIME (SWITCH_TO_YELLOW_RED_TIME + YELLOW_RED_TIME)
#define SWITCH_TO_YELLOW_TIME (SWITCH_TO_GREEN_TIME + GREEN_TIME)

#define B_OFFSET 30

void set_lights(int light_time) {
  if(timing == B) {
    light_time = (light_time + B_OFFSET) % CYCLE_TIME;
  }

  int red = 0;
  int yellow = 0;
  int green = 0;

  if(light_time < SWITCH_TO_YELLOW_RED_TIME) {
    red = 1;
  } else if(light_time < SWITCH_TO_GREEN_TIME) {
    red = 1;
    yellow = 1;
  } else if(light_time < SWITCH_TO_YELLOW_TIME) {
    green = 1;
  } else {
    yellow = 1;
  }

  // all off
  PORTB &= ~((1 << RED_PIN) | (1 << YELLOW_PIN) | (1 << GREEN_PIN));
  // turn only the right ones on
  PORTB |= (red << RED_PIN) | (yellow << YELLOW_PIN) | (green << GREEN_PIN);
}


ISR(TIM0_OVF_vect) {
   if (++timer_overflow_count > 5) {   // a timer overflow occurs 4.6 times per second
      light_time = (light_time+1) % CYCLE_TIME;
      set_lights(light_time);
      timer_overflow_count = 0;
   }
}

int main(void) {
   // Set LED ports to output
   DDRB = 1<<RED_PIN | 1<<YELLOW_PIN | 1<<GREEN_PIN;

   // prescale timer to 1/1024th the clock rate
   TCCR0B |= (1<<CS02) | (1<<CS00);

   // enable timer overflow interrupt
   TIMSK |=1<<TOIE0;
   sei();

   while(1) {
      // let ISR handle the LEDs forever
   }
}
{'fraction_non_alphanumeric': 0.10519031141868512, 'fraction_numerical': 0.025951557093425604, 'mean_word_length': 3.282962962962963, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '426826', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1038, 'n_words': 322}