コード例 #1
0
static void led_rotation_rotate_leds_triple(void) {
	static uint16_t count;
	count++;

	led_all_on();
	static const uint16_t count_max = 100;
	if (count % count_max < count_max / 4) {
		CLEAR_LED(LED_1);
	} else if (count % count_max < count_max / 2) {
		CLEAR_LED(LED_2);
	} else if (count % count_max < 3 * count_max / 4) {
		CLEAR_LED(LED_3);
	} else {
		CLEAR_LED(LED_4);
	}
}
コード例 #2
0
ファイル: main.c プロジェクト: kimooz/Line-follower
int main(void)
{

    char millis_str[16] = "0";
    char temp_str[16] = "0";
    unsigned long delay = 1000;
    unsigned long start_millis;
    unsigned char i = 0;

    init();

    sei(); // set global interrupt

    ADCSRA |= (1<<ADSC);
    uart_puts_p(PSTR("Hello World\n\r"));

    //_delay_ms(1000);

    start_millis = millis;

    ADMUX = (ADMUX&0xF0)|(0x04);

    for(;;)
    {
        if( (millis - start_millis) == delay)
        {
//            uart_puts_P("millis = ");
//            utoa(millis,millis_str,10);
//            uart_puts(millis_str);
//            uart_puts_P("\n\r");


            send_sensors();

            //send_sensor(0);


            start_millis = millis;
            //TOGGLE_LED();
            ADC_flag = 1;
            ADCSRA |= (1<<ADSC);
            CLEAR_LED();

        }
    }

    return 0;
}
コード例 #3
0
void led_all_off(void) {
	for (uint8_t i = 0; i < LED_COUNT; i++) {
		CLEAR_LED(leds[i]);
	}
}
コード例 #4
0
ファイル: STM32W_Radio.c プロジェクト: ndpr43/CpE5170
/*******************************************************************************
* Function Name  : radio_loop
* Description    : When Radio is idle then checks for packets to be transmitted
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void radio_loop()
{
	// if the TX is idle then dequeue next packet and start TX
	CLEAR_LED(RLED);
	if ( 1 == stradio_retransmit_req_)
	{
		#if defined(_ENABLE_XBEE_COMPAT_4BS_TX_) || defined(_FORCE_XBEE_COMPAT_TX_)
			#ifdef _FORCE_XBEE_COMPAT_TX_
				if (1)
			#else
         	   if (BS_ADDR == txPacket[6])
			#endif //_FORCE_XBEE_COMPAT_TX_
         	   {
					//txPacket[10]++;// = txPacket[3]; /* XBee COMPATIBILITY - increment sequence number */
					txPacket[3]++;
				}
		#endif // defined(_ENABLE_XBEE_COMPAT_4BS_TX_) || defined(_FORCE_XBEE_COMPAT_TX_)
		int temp_ret = ST_RadioTransmit(txPacket);
		if (ST_SUCCESS != temp_ret)
		{
			txComplete = TRUE; // FAILED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
			stradio_retransmision_result = temp_ret;
		}
		else
		{
			txComplete = FALSE;
			stradio_count_failed_retransmissions_++;
		}
		stradio_retransmit_req_ = 0;
	} else
	if (FALSE == txComplete)
	{
		SET_LED(RLED);
		count_stalled++;
		if (count_stalled > stalled_reset)
		{
			//stalled_reset = count_stalled + STALLED_THRESHOLD;
			//txComplete = TRUE;
		}
	} else if ( 0 != stradio_pending_len_ )
	{
		sendPacketData( stradio_pending_len_, stradio_pending_data_, stradio_pending_dst_);
		stradio_pending_len_ = 0;
	} else if ( ( 0 == pkt_to_sent_len ) && ( 0xFF == pkt_to_sent_id ) )
	{
		stalled_reset++;
		pkt_to_sent_id = que_deQpackets();
		if ( 0xFF != pkt_to_sent_id )
		{
			char routed = 0;
			unsigned int base = QBUFF_BASE ( pkt_to_sent_id );
			// fill the TX-related variables
			pkt_to_sent_len = PAK_GET_TOTAL_LENGTH ( pkt_to_sent_id );
			// routing decisions for the packet
			routed = routing_send_DATA_base ( QBUFF_BASE ( pkt_to_sent_id ) );
			// If routing OK then start transmission process -> backoff
			if ( 1 == routed )
			{
				unsigned int mac_d = get_dst_mac_base ( base );
				sent_DATA_ = 1;
				sendPacketData(pkt_to_sent_len, (sint8_t*)&(QBUFF_ACCESS(base, 0)) , mac_d ); // send via the backoff implementation
				phy_sent_timeout_ = rtc_get_ticks() + my_tx_timeout_;
				SET_LED(YLED);
			}
			else
			{
				if (ROUTING_BEGAN_ROUTE_DISCOVERY == routed)
				{
					// re-enqueue the packet
					if (0 == que_enQpacket (pkt_to_sent_id))
					{
						release_pkt_in_tx();
					}
					else
					{
						pkt_to_sent_len = 0;
						pkt_to_sent_id = 0xFF;
					}
				}
				else
				{
#ifdef _ENABLE_APP_MOD_
					app_drop_pkt ( pkt_to_sent_id, MODULE_RTR, REASON_NOROUTE, EVENT_DSEND );
#endif // _ENABLE_APP_MOD_
					// drop packet if not routable
					release_pkt_in_tx();
				}
			}
		}
	}
}