I got the Serial to work. Now i can get strings, but now when i include this
if (data == "OFF")
{
for (int i = 0; i < 7; i++)
{
Palatis::SoftPWM.set(pwmLEDsLeft*, 1);*
_ Palatis::SoftPWM.set(pwmLEDsRight*, 1);_
_ }_
_ }[/quote]_
my code crashes. And arduino does not do anything it works like one sec and then stops working.
Full code is here:
> #define SOFTPWM_OUTPUT_DELAY*
> #include <SoftPWM.h> // Include Palatis SoftPWM libary GitHub - Palatis/arduino-softpwm: Software PWM library for Arduino
> SOFTPWM_DEFINE_CHANNEL(3, DDRD, PORTD, PORTD3); // Arduino pin 3
> SOFTPWM_DEFINE_CHANNEL(5, DDRD, PORTD, PORTD5); // Arduino pin 5
> SOFTPWM_DEFINE_CHANNEL(6, DDRD, PORTD, PORTD6); // Arduino pin 6
> SOFTPWM_DEFINE_CHANNEL(7, DDRD, PORTD, PORTD7); // Arduino pin 7
> SOFTPWM_DEFINE_CHANNEL(8, DDRB, PORTB, PORTB0); // Arduino pin 8
> SOFTPWM_DEFINE_CHANNEL(9, DDRB, PORTB, PORTB1); // Arduino pin 9
> SOFTPWM_DEFINE_CHANNEL(10, DDRB, PORTB, PORTB2); // Arduino pin 10
> SOFTPWM_DEFINE_CHANNEL(11, DDRB, PORTB, PORTB3); // Arduino pin 11
> SOFTPWM_DEFINE_CHANNEL(12, DDRB, PORTB, PORTB4); // Arduino pin 12
> SOFTPWM_DEFINE_CHANNEL(13, DDRB, PORTB, PORTB5); // Arduino pin 13
> SOFTPWM_DEFINE_CHANNEL(14, DDRC, PORTC, PORTC0); // Arduino pin A0
> SOFTPWM_DEFINE_CHANNEL(15, DDRC, PORTC, PORTC1); // Arduino pin A1
> SOFTPWM_DEFINE_CHANNEL(16, DDRC, PORTC, PORTC2); // Arduino pin A2
> SOFTPWM_DEFINE_CHANNEL(17, DDRC, PORTC, PORTC3); // Arduino pin A3
> SOFTPWM_DEFINE_OBJECT_WITH_PWM_LEVELS(14, 102); // Define how many pwm channels project uses and how many steps it has
> // MSGEQ7 bands = 63Hz, 160Hz, 400Hz, 1,000Hz, 2,500Hz, 6,250Hz, 16,000Hz
> static volatile uint8_t v = 0;
> int ctrlReset = 2; // Digital pin 2 = signal to reset MSGEQ7s
> int ctrlStrobe = 4; // Digital pin 4 = signal to strobe (read data from) MSGEQ7s
> int channelLeft = A5; // Analog pin A5 = spectrum data from left channel
> int channelRight = A4; // Analog pin A4 = spectrum data from right channel
> int spectrumLeft[7]; // Array to store 7 bands of spectrum data from left channel
> int spectrumRight[7]; // Array to store 7 bands of spectrum data from right channel
> int pwmLEDsLeft[] = {3, 5, 6, 7, 8, 9, 10}; // Array to store data where leds are connected.
> int pwmLEDsRight[] = {11, 12, 13, 14, 15, 16, 17}; // Array to store data where leds are connected.
> int brightness = 50;
> String data = "ON"; // Mode ON = Music, 2 = Still, Anything else = off
> String bluetooth;
>
> void setup()
> {
> Serial.begin(9600);
> pinMode(ctrlReset, OUTPUT); // Define reset as output
> pinMode(ctrlStrobe, OUTPUT); // Define strobe as output
> digitalWrite(ctrlReset, LOW); // Pull the reset signal low
> digitalWrite(ctrlStrobe, HIGH); // Drive the strobe signal high
> Palatis::SoftPWM.begin(60); // Begin with 60hz pwm frequency
> //Palatis::SoftPWM.printInterruptLoad(); // Print interrupt load for diagnostic purposes
> }
>
>
> void loop()
> {
> while (Serial.available())
> {
> delay(10);
> char c = Serial.read();
> if (c == ':')
> {
> break;
*> } *
> bluetooth += c;
> }
> if (bluetooth.length() > 0) {
> data = bluetooth;
> bluetooth="";
> }
> if (data == "ON")
> {
> readMSGEQ7();
> writeLEDs();
> }
> if (data == "OFF")
> {
> for (int i = 0; i < 7; i++)
> {
> Palatis::SoftPWM.set(pwmLEDsLeft*, 1);*
> _ Palatis::SoftPWM.set(pwmLEDsRight*, 1);_
> _ }_
> _ }_
> _ Serial.print(data);_
> _ Serial.print("\n");_
> _}_
> void readMSGEQ7()
> _{ // Read the seven spectrum bands from the MSGEQ7 chips*
> * digitalWrite(ctrlReset, HIGH); // Pulse the reset signal, which causes*
> * digitalWrite(ctrlReset, LOW); // the MSGEQ7s to latch the spectrum values*
> * delayMicroseconds(72); // Delay to meet minimum reset-to-strobe time*
> * int nF = 50; // Noise filter level.*
> * for (int i = 0; i < 7; i++) // Cycle through the 7 spectrum bands*
> * {*
> * digitalWrite(ctrlStrobe, LOW); // Read current band (then increment to next band)*
> * delayMicroseconds(36); // Wait for outputs to settle*
> spectrumLeft = analogRead(channelLeft) / 10; // Store current values from left & right channels
> spectrumRight = analogRead(channelRight) / 10; // Divide 0-1023 by 10 to give about 0-100
> //if (spectrumLeft < nF) spectrumLeft = 0; // Noise filter left
> //if (spectrumRight < nF) spectrumRight = 0; // Noise filter right
> * digitalWrite(ctrlStrobe, HIGH);
> delayMicroseconds(36); // Delay to meet minimum strobe-to-strobe time*
> * }
> }
> void writeLEDs()
> {
> for (int i = 0; i < 7; i++) {
> Palatis::SoftPWM.set(pwmLEDsLeft, spectrumLeft);
> Palatis::SoftPWM.set(pwmLEDsRight, spectrumRight);
> Serial.print(spectrumLeft);
> if (spectrumLeft < 10) Serial.print(" ");
> Serial.print(" ");
> Serial.print(spectrumRight);
> if (spectrumRight < 10) Serial.print(" ");
> Serial.print(" | ");
> }
> Serial.print("\n");
> }
> [/quote]*_