asrpro 使用pca9685 模块

2023-10-10 17:12
文章标签 模块 使用 asrpro pca9685

本文主要是介绍asrpro 使用pca9685 模块,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

使用asrpro自带的asr_softiic.h 和 arduino Adafruit_PWMServoDriver驱动库

修改处

softiic.start(_i2caddr<<1|0); // 写 0 ,读 1 (地址要左移一位

注释requestfrom ; return 0

#include "asr.h"
extern "C"{ void * __dso_handle = 0 ;}
#include "setup.h"
#include "HardwareSerial.h"
#include "asr_softiic.h"uint32_t snid;
void hardware_init();
void LED();
void ASR_CODE();#define PCA9685_SUBADR1 0x2
#define PCA9685_SUBADR2 0x3
#define PCA9685_SUBADR3 0x4#define PCA9685_MODE1 0x0
#define PCA9685_PRESCALE 0xFE#define LED0_ON_L 0x6
#define LED0_ON_H 0x7
#define LED0_OFF_L 0x8
#define LED0_OFF_H 0x9#define ALLLED_ON_L 0xFA
#define ALLLED_ON_H 0xFB
#define ALLLED_OFF_L 0xFC
#define ALLLED_OFF_H 0xFDclass Adafruit_PWMServoDriver {public:Adafruit_PWMServoDriver(uint8_t addr = 0x40);void begin(void);void reset(void);void setPWMFreq(float freq);void setPWM(uint8_t num, uint16_t on, uint16_t off);void setPin(uint8_t num, uint16_t val, bool invert=false);private:uint8_t _i2caddr;uint8_t read8(uint8_t addr);void write8(uint8_t addr, uint8_t d);
};// class MySoftIIC
// {
//   public:
//   void begin(){softiic.begin(0,1);}
//   void stop(){softiic.stop();}
//   void write(uint8_t d){softiic.write(d);}
//   uint8_t read(bool b ){softiic.read(b);}
//   void requestFrom(uint8_t addr,uint8_t d){};//   int start(uint8_t addr){return softiic.start(addr<<1|0);}
//   void beginTransmission(uint8_t addr){start(addr);}
//   void stop(){softiic.stop();}
// };// MySoftIIC WIRE;// Set to true to print some debug messages, or false to disable them.
#define ENABLE_DEBUG_OUTPUT falseAdafruit_PWMServoDriver::Adafruit_PWMServoDriver(uint8_t addr) {_i2caddr = addr;
}void Adafruit_PWMServoDriver::begin(void) {softiic.begin(0,1);reset();
}void Adafruit_PWMServoDriver::reset(void) {write8(PCA9685_MODE1, 0x0);
}void Adafruit_PWMServoDriver::setPWMFreq(float freq) {//Serial.print("Attempting to set freq ");//Serial.println(freq);freq *= 0.9;  // Correct for overshoot in the frequency setting (see issue #11).float prescaleval = 25000000;prescaleval /= 4096;prescaleval /= freq;prescaleval -= 1;if (ENABLE_DEBUG_OUTPUT) {Serial.print("Estimated pre-scale: "); Serial.println(prescaleval);}uint8_t prescale = floor(prescaleval + 0.5);if (ENABLE_DEBUG_OUTPUT) {Serial.print("Final pre-scale: "); Serial.println(prescale);}uint8_t oldmode = read8(PCA9685_MODE1);uint8_t newmode = (oldmode&0x7F) | 0x10; // sleepwrite8(PCA9685_MODE1, newmode); // go to sleepwrite8(PCA9685_PRESCALE, prescale); // set the prescalerwrite8(PCA9685_MODE1, oldmode);delay(5);write8(PCA9685_MODE1, oldmode | 0xa1);  //  This sets the MODE1 register to turn on auto increment.// This is why the beginTransmission below was not working.//  Serial.print("Mode now 0x"); Serial.println(read8(PCA9685_MODE1), HEX);
}void Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on, uint16_t off) {//Serial.print("Setting PWM "); Serial.print(num); Serial.print(": "); Serial.print(on); Serial.print("->"); Serial.println(off);softiic.start(_i2caddr<<1|0);softiic.write(LED0_ON_L+4*num);softiic.write(on);softiic.write(on>>8);softiic.write(off);softiic.write(off>>8);softiic.stop();
}// Sets pin without having to deal with on/off tick placement and properly handles
// a zero value as completely off.  Optional invert parameter supports inverting
// the pulse for sinking to ground.  Val should be a value from 0 to 4095 inclusive.
void Adafruit_PWMServoDriver::setPin(uint8_t num, uint16_t val, bool invert)
{// Clamp value between 0 and 4095 inclusive.if(val > 4095)val = 4095;if (invert) {if (val == 0) {// Special value for signal fully on.setPWM(num, 4096, 0);}else if (val == 4095) {// Special value for signal fully off.setPWM(num, 0, 4096);}else {setPWM(num, 0, 4095-val);}}else {if (val == 4095) {// Special value for signal fully on.setPWM(num, 4096, 0);}else if (val == 0) {// Special value for signal fully off.setPWM(num, 0, 4096);}else {setPWM(num, 0, val);}}
}uint8_t Adafruit_PWMServoDriver::read8(uint8_t addr) {softiic.start(_i2caddr<<1|0);softiic.write(addr);softiic.stop();//softiic.requestFrom((uint8_t)_i2caddr, (uint8_t)1);//return softiic.read();return 0;
}void Adafruit_PWMServoDriver::write8(uint8_t addr, uint8_t d) {softiic.start(_i2caddr<<1|0);softiic.write(addr);softiic.write(d);softiic.stop();
}Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();//--------------------------------------------------------///**************************************************************
bool bl = 0;
int i=0;
void LED(){while (1) {//扫描设备 for(int i = 1;i<0x7f;i++){// int val = softiic.start(i<<1 | 0);// softiic.stop();// Serial.print(i,HEX);// Serial.print("ox ");// Serial.println(val,HEX);pwm.begin();pwm.setPWMFreq(1600);pwm.setPin(4,i*46,0);delay(100);}}vTaskDelete(NULL);
}
//------------------------------------------------void setup()
{Serial.begin(9600);delay(100);//softiic.begin(0,1);pinMode(4,output);setPinFun(4,FIRST_FUNCTION);digitalWrite(4,0);//{speak:小蝶-清新女声,vol:10,speed:10,platform:haohaodada}//{playid:10001,voice:欢迎使用语音助手,用天问五幺唤醒我。}//{playid:10002,voice:我退下了,用天问五幺唤醒我}//{ID:0,keyword:"唤醒词",ASR:"天问五幺",ASRTO:"我在"}//{ID:1,keyword:"命令词",ASR:"打开灯光",ASRTO:"好的,马上打开灯光"}//{ID:2,keyword:"命令词",ASR:"关闭灯光",ASRTO:"好的,马上关闭灯光"}xTaskCreate(hardware_init,"hardware_init",256,NULL,100,NULL);
}//--------------------------------------------------------//{ID:250,keyword:"命令词",ASR:"最大音量",ASRTO:"音量调整到最大"}
//{ID:251,keyword:"命令词",ASR:"中等音量",ASRTO:"音量调整到中等"}
//{ID:252,keyword:"命令词",ASR:"最小音量",ASRTO:"音量调整到最小"}
void hardware_init(){xTaskCreate(LED,"LED",256,NULL,4,NULL);vTaskDelete(NULL);
}/*描述该功能...
*/
void ASR_CODE(){switch (snid) {case 1://digitalWrite(4,0);break;case 2://digitalWrite(4,1);break;}}

这篇关于asrpro 使用pca9685 模块的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/181910

相关文章

Spring IoC 容器的使用详解(最新整理)

《SpringIoC容器的使用详解(最新整理)》文章介绍了Spring框架中的应用分层思想与IoC容器原理,通过分层解耦业务逻辑、数据访问等模块,IoC容器利用@Component注解管理Bean... 目录1. 应用分层2. IoC 的介绍3. IoC 容器的使用3.1. bean 的存储3.2. 方法注

Python内置函数之classmethod函数使用详解

《Python内置函数之classmethod函数使用详解》:本文主要介绍Python内置函数之classmethod函数使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录1. 类方法定义与基本语法2. 类方法 vs 实例方法 vs 静态方法3. 核心特性与用法(1编程客

Linux中压缩、网络传输与系统监控工具的使用完整指南

《Linux中压缩、网络传输与系统监控工具的使用完整指南》在Linux系统管理中,压缩与传输工具是数据备份和远程协作的桥梁,而系统监控工具则是保障服务器稳定运行的眼睛,下面小编就来和大家详细介绍一下它... 目录引言一、压缩与解压:数据存储与传输的优化核心1. zip/unzip:通用压缩格式的便捷操作2.

使用Python实现可恢复式多线程下载器

《使用Python实现可恢复式多线程下载器》在数字时代,大文件下载已成为日常操作,本文将手把手教你用Python打造专业级下载器,实现断点续传,多线程加速,速度限制等功能,感兴趣的小伙伴可以了解下... 目录一、智能续传:从崩溃边缘抢救进度二、多线程加速:榨干网络带宽三、速度控制:做网络的好邻居四、终端交互

Python中注释使用方法举例详解

《Python中注释使用方法举例详解》在Python编程语言中注释是必不可少的一部分,它有助于提高代码的可读性和维护性,:本文主要介绍Python中注释使用方法的相关资料,需要的朋友可以参考下... 目录一、前言二、什么是注释?示例:三、单行注释语法:以 China编程# 开头,后面的内容为注释内容示例:示例:四

Python中re模块结合正则表达式的实际应用案例

《Python中re模块结合正则表达式的实际应用案例》Python中的re模块是用于处理正则表达式的强大工具,正则表达式是一种用来匹配字符串的模式,它可以在文本中搜索和匹配特定的字符串模式,这篇文章主... 目录前言re模块常用函数一、查看文本中是否包含 A 或 B 字符串二、替换多个关键词为统一格式三、提

Go语言数据库编程GORM 的基本使用详解

《Go语言数据库编程GORM的基本使用详解》GORM是Go语言流行的ORM框架,封装database/sql,支持自动迁移、关联、事务等,提供CRUD、条件查询、钩子函数、日志等功能,简化数据库操作... 目录一、安装与初始化1. 安装 GORM 及数据库驱动2. 建立数据库连接二、定义模型结构体三、自动迁

ModelMapper基本使用和常见场景示例详解

《ModelMapper基本使用和常见场景示例详解》ModelMapper是Java对象映射库,支持自动映射、自定义规则、集合转换及高级配置(如匹配策略、转换器),可集成SpringBoot,减少样板... 目录1. 添加依赖2. 基本用法示例:简单对象映射3. 自定义映射规则4. 集合映射5. 高级配置匹

Spring 框架之Springfox使用详解

《Spring框架之Springfox使用详解》Springfox是Spring框架的API文档工具,集成Swagger规范,自动生成文档并支持多语言/版本,模块化设计便于扩展,但存在版本兼容性、性... 目录核心功能工作原理模块化设计使用示例注意事项优缺点优点缺点总结适用场景建议总结Springfox 是

嵌入式数据库SQLite 3配置使用讲解

《嵌入式数据库SQLite3配置使用讲解》本文强调嵌入式项目中SQLite3数据库的重要性,因其零配置、轻量级、跨平台及事务处理特性,可保障数据溯源与责任明确,详细讲解安装配置、基础语法及SQLit... 目录0、惨痛教训1、SQLite3环境配置(1)、下载安装SQLite库(2)、解压下载的文件(3)、