Exemplo n.º 1
0
int main(void)
{
    analogvalue_t delay;

    setup();
    setup_timer0();

    // setup_int0();

    // display_off(&display);
    setup_timer2();

    analog_init(&delay);
    potentiometer_read(&delay);

    display_set(&display, delay.v);
    display_on(&display, 1);

    /* if ((PIND & _BV(PIN_SW1)) == 0) */
    /*     pin = PIN_LED_RED; */

    for (;;) {
        if ((PIND & _BV(PIN_BUTTON2)) == 0) {
            PORTB &= _BV(PIN_LED);
        } else {
            PORTB |= _BV(PIN_LED);
        }



/*
        if ((PIND & _BV(PIN_SW1)) == 0) {
            long tmax = 1000L * delay.v;
            while (micros() - t0 < tmax)
                ;
            PORTD |= _BV(pin);
        } else {
            PORTD &= ~_BV(pin);
            enable_int0();
        }

        if ((PIND & _BV(PIN_SW2)) == 0) {
            settle_on_low(&PIND, PIN_SW2);
            loop_until_bit_is_set(PIND, PIN_SW2);
            display_toggle(&display);
        }
*/

        potentiometer_read(&delay);
        if (delay.v != display.value) {
            display_set(&display, delay.v);
        }
    }

    return 0;
}
Exemplo n.º 2
0
int main(void)
{
	uint8_t i;

	cli();
	MCUSR = 0;
	wdt_disable();

	//TODO replace by an ana comp polling loop
	_delay_ms(10);

	setup_datastructs();
	setup_led();
	setup_ar_uart();
	setup_adc();
	setup_pulse_input();
	setup_analog_comparator();
	setup_timer0();
	setup_timer1();
	
	// initialize the CTRL buffers
	ctrlInit();
	// initialize the SPI in slave mode
	setup_spi(SPI_MODE_0, SPI_MSB, SPI_INTERRUPT, SPI_SLAVE);

	// initialize the Si4421/RFM12 radio and buffers
	rfm12_init();

	// the clk/8 fuse bit is set
	clock_prescale_set(clock_div_1);
	FLAG_CLR_ICF1();
	sei();


	for(;;) {
		if (spi_status & SPI_NEW_CTRL_MSG) {
			ctrlDecode();
			spi_status &= ~SPI_NEW_CTRL_MSG;
		}

		for (i = 0; i < max_analog_sensors; i++) {
			if (state[i].flags & STATE_POWER_CALC) {
				calculate_power(&state[i]);
				state[i].flags &= ~STATE_POWER_CALC;
				state[i].flags |= STATE_POWER;
			}
		}

		rfm12_tick();
	}

	return 0;
}
Exemplo n.º 3
0
int main(void)
{
    setup_pins();
    setup_comparator();
    setup_timer0();

    ledsetup();
    uint8_t message_buffer[12] = {0};
    Controller *controller = (Controller*)message_buffer;
    machine_init();

    Animation anim;
    clear_animation(&anim);
    bool prev_machine_toggle = true;

    delay_ms(1000);

    while(1)
    {
        // Wait until we have a valid message
        while(!getMessage(message_buffer)) {}

        // Interpret the input
        process_input(controller, &anim); 

        if((prev_machine_toggle && !machine_toggle) ||
            machine_toggle)
        { 
            show_animation(&anim);
        }
        clear_animation(&anim);
        prev_machine_toggle = machine_toggle;

        // Wait for the 2nd paired request to pass
        _delay_us(2000);
    }
}
Exemplo n.º 4
0
Arquivo: main.c Projeto: alohr/avr
int main(void)
{
    timer tping = { 0, 0 };
    decode_results r;
    state s;
    counter cping;

    memset(&r, 0, sizeof r);
    memset(&s, 0, sizeof s);

    memset(&cping, 0, sizeof cping);

    /*
     * PB0 ir receiver input
     * PB1 servo control out (OC1A)
     * PB2 motor2 enable (OC1B)
     * PB4 ping sensor
     *
     * PD3 motor1 control out A
     * PD4 motor1 control out B
     * PD6 motor2 control out A
     * PD7 motor2 control out B
     */

    DDRB = _BV(PB1) | _BV(PB2);
    PORTB = ~(_BV(PB1) | _BV(PB2) | _BV(PB4));  /* enable pull-ups, leave PB4 alone */

    DDRD = 0xd8;
    PORTD = 0x27; /* enable pull-ups */

    setup_timer0();
    setup_pwm1();
    setup_irrecv();

    for (;;) {
	if (irrecv_decode(&r)) {
	    irinterpret(&s, &r);
	    irrecv_resume();
	}

	// switch motor0 off after a short period of time
	if (s.run0 && millis() - s.timestamp0 > MOTOR0_TIMEOUT_MS)
	    s.run0 = 0;

	set_motor_pins(&s);
	set_servo_pins(&s);

	// ping every 50ms
	if ((tping.t = millis()) - tping.t0 > 50) {
	    tping.t0 = tping.t;

	    unsigned long us = ping(200);
	    if (us != ULONG_MAX) {
		// got a valid reading
 		unsigned long cm = us / ROUNDTRIP_CM_US;
		update_counter(&cping, cm);

		// motor1 running forward?
		if (s.run1 > MOTOR1_MIN) {
		    cm = average_counter(&cping);
		    if (cm < 40) {
			s.run1 = 0;
		    } else {
			int newrun1 = (cm - 40) / 4;
			if (newrun1 < s.run1)
			    if ((s.run1 = newrun1) < MOTOR1_MIN + 2)
				s.run1 = 0;
		    }
		    set_motor_pins(&s);
		}
 	    }
	}

    }

    return 0;
}