yue6315018 发表于 2015-7-25 13:01:46

[Mico]主板测试外设,电机,温湿度,OLED,红外...

简单测试了下板上各外设功能。未联网

http://v.youku.com/v_show/id_XMTI5MzEzODAxNg==.html

#include "MiCO.h"
#include "DHT11.h"
#include "rgb_led.h"
#include "oled.h"
#include "dc_motor.h"
#include "infrared_reflective.h"

extern void MicoNanosendDelay( uint64_t delayns );
void DHT11_Test(void);
void RgbLed_Test(void);
void OLED_Test(void);
void dc_motor_Test(void);
void infrared_Test(void);


unsigned char g_Warning = 0;
unsigned char g_OledClear = 0;

int application_start( void )
{

/* Output on serial debug port */
printf( "Hello World!\r\n" );

if (DHT11_Init())
{
      printf("DHT11 Init failed\r\n");
}

rgb_led_init();
OLED_Init();
dc_motor_init();
OLED_Test();
dc_motor_Test();
infrared_reflective_init();
while(1){
    DHT11_Test();
    RgbLed_Test();
    infrared_Test();
    MicoGpioOutputTrigger( MICO_SYS_LED );
    mico_thread_sleep( 1 );
}
}

void DHT11_Test(void)
{   
    unsigned char temperature, humidity;
    if (!g_Warning)
    {   
      DHT11_Read_Data(&temperature,&humidity);
      printf("Temperature : %d\r\n",temperature);
      printf("Humidity : %d\r\n",humidity);
      if (g_OledClear == 1)
      {
          g_OledClear = 0;
          OLED_Clear();
      }
      OLED_ShowString(0,0,"Hello Kitty!");
      OLED_ShowString(0,3,"Tem:");
      OLED_ShowString(0,6,"Hum:");
      OLED_ShowNum(50,3,temperature,2,16);
      OLED_ShowNum(50,6,humidity,2,16);
    }
}

void RgbLed_Test(void)
{
    static char i = 0;
    if (!g_Warning)
    {
      i++;
      if (i == 4)
            i = 1;
      if (i == 1)
          rgb_led_open(255,0,0);
      if (i == 2)
          rgb_led_open(0,255,0);
      if (i == 3)
          rgb_led_open(0,0,255);
    }
}

void OLED_Test(void)
{
    OLED_ShowString(0,0,"Hello Kitty!");
    OLED_ShowString(0,3,"Tem:");
    OLED_ShowString(0,6,"Hum:");
}

void dc_motor_Test(void)
{
    dc_motor_set(1);//Open motor
    dc_motor_set(0);
}

void infrared_Test(void)
{
unsigned short data;
static char lock = 0;

infrared_reflective_read(&data);
printf("data : %d\r\n",data);

if (data < 4000)
{
    printf("____有人闯入!!\r\n");
    if (lock == 0)
    {
      lock = 1;
      OLED_Clear();
    }
   
    OLED_ShowString(40,3,"H E L P ");
    OLED_ShowString(20,6,"Bad man IN");
    rgb_led_open(255,0,0);
    dc_motor_set(1);
   
    g_OledClear = 1;
    g_Warning = 1;
}
else
{
    lock = 0;
    g_Warning = 0;
    dc_motor_set(0);
}
}

aleyn 发表于 2015-7-25 15:01:57

H E L P,Bad man IN!{:lol:}

ANHOME 发表于 2015-7-29 14:01:35

最好能上传整个工程文件,呵呵!
页: [1]
查看完整版本: [Mico]主板测试外设,电机,温湿度,OLED,红外...