示例#1
0
int main (void) 
{ 
  long toggled;
  long swatch, btndur;
  uint8_t btnstate;
  
  SystemInit();
  SystemCoreClockUpdate();  

  start_delay();
  GPIOInit();
  
  pinMode(USERBTN, INPUT);
  pinMode(USERLED, OUTPUT);
  pinMode(LCDBKLT, OUTPUT);
  
  PWM0_tone(PIO1_13, 1320, 100);
	PWM0_tone(PIO1_13, 1540, 100);

  toggled = millis();
  btnstate = HIGH;

  while (1)                                /* Loop forever */
  {
    if ( btnstate == HIGH && digitalRead(PIO0_1) == LOW ) {
      btnstate = LOW;
      swatch = millis();
    } else
    if ( btnstate == LOW && digitalRead(PIO0_1) == HIGH ) {
      btnstate = HIGH;
      if ( millis() >= swatch + 10 ) {
        btndur = millis() - swatch;
      } else {
        btndur = 0;
      }
      if ( btndur > 667 ) {
        digitalToggle(LCDBKLT);
        PWM0_tone(PIO0_8, 1320, 100);
        PWM0_tone(PIO0_8, 1540, 100);
      } else {
        PWM0_tone(PIO0_8, 1100, 100);
        PWM0_tone(PIO0_8, 880, 100);
      }
    }
    if ( millis() >= toggled + 1000 ) {
      digitalToggle(USERLED);
      toggled = millis();
    }
  }
}
示例#2
0
void signalLED(LEDNUM_t led_num, LEDMODE_t led_mode)
{
	switch (led_mode)
	{

	case LEDMODE_OFF:
		digitalLo(gpio_cfg[led_num].gpio, gpio_cfg[led_num].pin);
		break;

	case LEDMODE_ON:
		digitalHi(gpio_cfg[led_num].gpio, gpio_cfg[led_num].pin);
		break;

	case LEDMODE_TOGGLE:
		digitalToggle(gpio_cfg[led_num].gpio, gpio_cfg[led_num].pin);
		break;

	case LEDMODE_BLINK1:
		digitalHi(gpio_cfg[led_num].gpio, gpio_cfg[led_num].pin);
		xTimerChangePeriod(LedTimer[led_num], 500, 10);
		break;

	case LEDMODE_BLINK2:

		break;
	}
}
示例#3
0
文件: digital.c 项目: epccs/irrigate7
// digitalToggle( arg[0] )
void Toggle(void)
{
    if ( (command_done == 10) )
    {
        // check that arg[0] is a digit 
        if ( ( !( isdigit(arg[0][0]) ) ) )
        {
            printf_P(PSTR("{\"err\":\"dTogNaN\"}\r\n"));
            initCommandBuffer();
            return;
        }
        // and arg[0] value is 2|3|24|25|26|27  
        uint8_t a = atoi(arg[0]);
        if ( (a != 2) && (a != 3) && ( ( a < 24) || (a > 27) ) )
        {
            printf_P(PSTR("{\"err\":\"dTogOutOfRng\"}\r\n"));
            initCommandBuffer();
            return;
        }
        serial_print_started_at = millis();
        digitalToggle(a);
        
        printf_P(PSTR("{\""));
        command_done = 11;
    }
    else if ( (command_done == 11) )
    {  
        echo_digital_pin_in_json_rply();
        printf_P(PSTR("\":\""));
        command_done = 12;
    }
    else if ( (command_done == 12) )
    {
        uint8_t a = atoi(arg[0]);
        if ( (a > (NUM_DIGITAL_PINS-1)) ) // the badPinCheck will barf at compile time without testing the value ... amazing
        {
            return;
        }
        bool pin = digitalRead(a);
        if (pin)
        {
            printf_P(PSTR("HIGH"));
        }
        else
        {
            printf_P(PSTR("LOW"));
        }
        printf_P(PSTR("\"}\r\n"));
        initCommandBuffer();
    }
    else
    {
        printf_P(PSTR("{\"err\":\"dTogCmdDnWTF\"}\r\n"));
        initCommandBuffer();
    }
}
示例#4
0
文件: main.c 项目: epccs/irrigate7
void blink(void)
{
    unsigned long kRuntime = millis() - blink_started_at;
    if ( kRuntime > blink_delay)
    {
        digitalToggle(STATUS_LED);
        
        // next toggle 
        blink_started_at += blink_delay; 
    }
}
示例#5
0
void SSerial_recv(void)
{
  UINT8 d = 0;

  if(_inverse_logic ? SSerial_rx_pin_read() : !SSerial_rx_pin_read())
  {
    tunedDelay(_rx_delay_centering);
    digitalToggle(_DEBUG_PIN); // Debug

    for(UINT8 i = 1; i; i <<= 1)
    {
      tunedDelay(_rx_delay_intrabit);
      digitalToggle(_DEBUG_PIN); // Debug
      UINT8 noti = ~i;
      if(SSerial_rx_pin_read())
        d |= i;
      else // else clause added to ensure function timing is ~balanced
        d &= noti;
    }

    // skip the stop bit
    tunedDelay(_rx_delay_stopbit);
    digitalToggle(_DEBUG_PIN); // Debug

    if(_inverse_logic)
      d = ~d;

    // if buffer full, set the overflow flag and return
    if((_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF != _receive_buffer_head)
    {
      // save new data in buffer: tail points to where byte goes
      _receive_buffer[_receive_buffer_tail] = d; // save new byte
      _receive_buffer_tail = (_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF;
    }
    else
    {
//      DebugPulse(_DEBUG_PIN1, 1);
      _buffer_overflow = true;
    }
  }
}
示例#6
0
void STM_EVAL_LEDToggle(Led_TypeDef Led) { digitalToggle(Led); }
示例#7
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
	RCC_ClocksTypeDef RCC_Clocks;
	char tmp[64];
	
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */  

	cmcore_init();
	//TIM2_delay_start();
	//usart_init(&stdserial, USART3, PB11, PB10, 19200);
  /* SysTick end of count event each 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
//  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
	
//	usart_init(&stdserial, USART3, PB11, PB10, 57600);
	sprintf(tmp, "SYSCLK = %ld\n", RCC_Clocks.SYSCLK_Frequency);
	usart_print(&stdserial, tmp);
	sprintf(tmp, "HCLK = %ld\n", RCC_Clocks.HCLK_Frequency);
	usart_print(&stdserial, tmp);
	sprintf(tmp, "PCLK1 = %ld\n", RCC_Clocks.PCLK1_Frequency);
	usart_print(&stdserial, tmp);
	sprintf(tmp, "PCLK2 = %ld\n", RCC_Clocks.PCLK2_Frequency);
	usart_print(&stdserial, tmp);
//	usart_print(&stdserial, tmp);
	
  /* Initialize LEDs and LCD available on STM324xG-EVAL board *****************/
	pinMode(LED1_PIN, OUTPUT);
//  STM_EVAL_LEDInit(LED1);
//  STM_EVAL_LEDInit(LED2);
//  STM_EVAL_LEDInit(LED3);
//  STM_EVAL_LEDInit(LED4);

  /* Initialize the LCD */
	digitalWrite(LED1_PIN, HIGH); // Off
//  STM324xG_LCD_Init();
  /* Display message on STM324xG-EVAL LCD *************************************/
  /* Clear the LCD */ 
//  LCD_Clear(White);

  /* Set the LCD Back Color */
//  LCD_SetBackColor(Blue);
  /* Set the LCD Text Color */
//  LCD_SetTextColor(White);
//  LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1);
//  LCD_DisplayStringLine(LINE(1), (uint8_t *)MESSAGE2);
//  LCD_DisplayStringLine(LINE(2), (uint8_t *)MESSAGE3);

  /* Turn on LEDs available on STM324xG-EVAL **********************************/
	digitalWrite(LED1_PIN, HIGH);
//  STM_EVAL_LEDOn(LED1);
//  STM_EVAL_LEDOn(LED2);
//  STM_EVAL_LEDOn(LED3);
//  STM_EVAL_LEDOn(LED4);

  /* Add your application code here
     */
	pinMode(BUTTON1_PIN, INPUT);

  /* Infinite loop */
  while (1)
  {
    /* Toggle LD4 */
//    STM_EVAL_LEDToggle(LED4);
		digitalToggle(LED1_PIN);
    /* Insert 50 ms delay */
    delay(500);

    /* Toggle LD2 */
//    STM_EVAL_LEDToggle(LED2);
		digitalToggle(LED1_PIN);

    /* Insert 50 ms delay */
    delay(500);
		
		if ( digitalRead(BUTTON1_PIN) ) {
			usart_print(&stdserial, "Wow! ");
		} else {
			sprintf(tmp, "%ld\n", millis());
			usart_print(&stdserial, tmp);
		}
  }
}