im using an esp32-WROOM-32D
using ardunio as my IDE
Ive written code to control vibrating motors through a pot and leds mapped to the strength of the signal.
here is the main code. ive my library name excluded
Code: Select all
int motor=13;
int motor2=12;
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
Level_Leds ON(33,27,14,26);
void setup() {
Serial.begin(115200);
// put your setup code here, to run once:
pinMode(35,INPUT);//pot pin
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
ledcSetup(ledChannel, freq, resolution);
//attach the channel to the GPIO to be controlled
ledcAttachPin(motor, ledChannel);
ledcAttachPin(motor2, ledChannel);
}
void loop() {
int a=analogRead(35);//reads pot pin
int b=ON.Speed_Level(a);
ledcWrite(ledChannel, b);
library code
Code: Select all
Level_Leds::Level_Leds()//default constructor
{
int pins[] = { 22, 23, 24, 25 };
for (int z = 0; z < sizeof(pins); z++)
{
ledPins[z] = pins[z];
}
for (int n = 0; n < sizeof(ledPins); n++)
{
pinMode(ledPins[n], OUTPUT);
}
for (int n = 0; n < sizeof(ledPins); n++)
{
digitalWrite(ledPins[n], LOW);
}
}
Level_Leds::Level_Leds(int led1, int led2, int led3, int led4)//parameterized constructor
{
int pins[] = { led1, led2, led3, led4 };
for (int z = 0; z < sizeof(pins); z++)
{
ledPins[z] = pins[z];
}
for (int n = 0; n < sizeof(ledPins); n++)
{
pinMode(ledPins[n], OUTPUT);
}
for (int n = 0; n < sizeof(ledPins); n++)
{
digitalWrite(ledPins[n], LOW);
}
}
int Level_Leds::Speed_Level(int r)//writes to leds, returns vaule for motorspeed
{
const int ADC_Res = 4095;
const unsigned int increment = ADC_Res / sizeof(ledPins);//1024
int motortorun = r / increment;//pot vaule divided by 1024, range between 1-4;
for (int i = 0; i <= motortorun; i++)
{
digitalWrite(ledPins[i], HIGH);
}
for(int i =4;i>=motortorun;i--)
{
digitalWrite(ledPins[i], LOW);
}
int motorSpeed = r / 16.05 ;//4095/4-
return motorSpeed;
}
if I run the code without Level_Leds the motors run as expected.
if I run the code Level_Leds without the motor code it runs as expected.
but when both are in the same code I get
Code: Select all
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/queue.c:1443 (xQueueGenericReceive)- assert failed!
abort() was called at PC 0x40085ec9 on core 1
ELF file SHA256: 0000000000000000
Backtrace: 0x40084f08:0x3ffb1ea0 0x4008517d:0x3ffb1ec0 0x40085ec9:0x3ffb1ee0 0x400d1259:0x3ffb1f20 0x400d147d:0x3ffb1f60 0x400d0e77:0x3ffb1f80 0x400d27b6:0x3ffb1fb0 0x4008617d:0x3ffb1fd0
Rebooting...
any help would be greatly appreciated