单独亮红灯
/*
* Copyright (C) 2015-2020 Alibaba Group Holding Limited
*/
#include <aos/errno.h>
#include <aos/kernel.h>
#include <unistd.h>
#include <k_api.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <uservice/uservice.h>
#include <uservice/eventid.h>
#include "aos/init.h"
#include "board.h"
#include "aos/hal/gpio.h"
#include "aos/hal/pwm.h"
//#include "sh1106.h"
#include "aos/hal/adc.h"
#include "aos/hal/i2c.h"
#include "drv_als_ps_ir_liteon_ap3216c.h"
#include "ulog/ulog.h"
#include "netmgr.h"
#include "hal_iomux_haas1000.h"
#include "../../../components/lwip/lwip2.0.0/include/lwip/sockets.h"
gpio_dev_t red;
gpio_dev_t key1;
void handler_irq(void* arg){
if(1 == (int)arg)
{
hal_gpio_output_toggle(&red);//led电平反转
}
}
void myled_init(){
red.port=HAL_GPIO_PIN_P4_4;
red.config=OUTPUT_PUSH_PULL;
red.priv=NULL;
hal_gpio_init(&red);//初始化
hal_gpio_output_low(&red);//默认低电平
}
void mykey_init(){
key1.port = HAL_GPIO_PIN_P2_7;
key1.config =IRQ_MODE;
key1.priv=NULL;
hal_gpio_init(&key1);
hal_gpio_enable_irq(&key1,IRQ_TRIGGER_FALLING_EDGE,handler_irq,(void *)1);
}
int application_start(int argc, char *argv[])
{
myled_init();
mykey_init();
while (1)
{
aos_msleep(1000);
};
}
红绿蓝灯都亮
/*
* Copyright (C) 2015-2020 Alibaba Group Holding Limited
*/
#include <aos/errno.h>
#include <aos/kernel.h>
#include <unistd.h>
#include <k_api.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <uservice/uservice.h>
#include <uservice/eventid.h>
#include "aos/init.h"
#include "board.h"
#include "aos/hal/gpio.h"
#include "aos/hal/pwm.h"
#include "sh1106.h"
#include "aos/hal/adc.h"
#include "aos/hal/i2c.h"
#include "drv_als_ps_ir_liteon_ap3216c.h"
#include "ulog/ulog.h"
#include "netmgr.h"
#include "hal_iomux_haas1000.h"
#include "../../../components/lwip/lwip2.0.0/include/lwip/sockets.h"
gpio_dev_t red, green, blue;
gpio_dev_t key1, key2, key3;
void handler_irq(void* arg){
switch ((int)arg)
{
case 1:
hal_gpio_output_toggle(&red);
break;
case 2:
hal_gpio_output_toggle(&green);
break;
case 3:
hal_gpio_output_toggle(&blue);
break;
}
}
void myled_init(){
red.port=HAL_GPIO_PIN_P4_4;
red.config=OUTPUT_PUSH_PULL;
red.priv=NULL;
hal_gpio_init(&red);//初始化
hal_gpio_output_low(&red);//默认低电平
green.port=HAL_GPIO_PIN_P4_3;
green.config=OUTPUT_PUSH_PULL;
green.priv=NULL;
hal_gpio_init(&green);//初始化
hal_gpio_output_low(&green);//默认低电平
blue.port=HAL_GPIO_PIN_P4_2;
blue.config=OUTPUT_PUSH_PULL;
blue.priv=NULL;
hal_gpio_init(&blue);//初始化
hal_gpio_output_low(&blue);//默认低电平
}
void mykey_init(){
key1.port = HAL_GPIO_PIN_P2_7;
key1.config =IRQ_MODE;
key1.priv=NULL;
hal_gpio_init(&key1);
hal_gpio_enable_irq(&key1,IRQ_TRIGGER_FALLING_EDGE,handler_irq,(void *)1);
key2.port = HAL_GPIO_PIN_P2_4;
key2.config =IRQ_MODE;
key2.priv=NULL;
hal_gpio_init(&key2);
hal_gpio_enable_irq(&key2,IRQ_TRIGGER_FALLING_EDGE,handler_irq,(void *)2);
key3.port = HAL_GPIO_PIN_P2_5;
key3.config =IRQ_MODE;
key3.priv=NULL;
hal_gpio_init(&key3);
hal_gpio_enable_irq(&key3,IRQ_TRIGGER_FALLING_EDGE,handler_irq,(void *)3);
}
int application_start(int argc, char *argv[])
{
myled_init();
mykey_init();
while (1)
{
aos_msleep(1000);
};
}
蜂鸣器
/*
* Copyright (C) 2015-2020 Alibaba Group Holding Limited
*/
#include <aos/errno.h>
#include <aos/kernel.h>
#include <unistd.h>
#include <k_api.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <uservice/uservice.h>
#include <uservice/eventid.h>
#include "aos/init.h"
#include "board.h"
#include "aos/hal/gpio.h"
#include "aos/hal/pwm.h"
#include "sh1106.h"
#include "aos/hal/adc.h"
#include "aos/hal/i2c.h"
#include "drv_als_ps_ir_liteon_ap3216c.h"
#include "ulog/ulog.h"
#include "netmgr.h"
#include "hal_iomux_haas1000.h"
#include "../../../components/lwip/lwip2.0.0/include/lwip/sockets.h"
#define PWM_PORT 0
int application_start(int argc, char *argv[])
{
pwm_dev_t buzzer;
buzzer.port=PWM_PORT; //端口号
buzzer.config.duty_cycle=0.5; //占空比
buzzer.config.freq=2000; //频率
buzzer.priv=NULL; //私有数据
hal_pwm_init(&buzzer);//初始化引脚
while (1)
{
hal_pwm_start(&buzzer);//开是输出pwm方波
aos_msleep(100); //延时100ms
hal_pwm_stop(&buzzer);//停止输出pwm方波
aos_msleep(100); //延时100ms
};
}