millis () not working.

Hello,

I’ve been working on this project for quite some time now but i cant seem to get my servo’s to move slower and the lights fading.
The servo’s just jumps to position in the same speed and the leds just go on and of.

I’m using an arduino micro witch I tested with the blink without delay and fading sketches, they both do what they are supposed to do.

I think I have the fading without delay correct, and the servo stuff as well. But i cant for the life of me get it to work.

Here is my code;

  • the digitalwrite on pin 13 is just for testing purposes.
  • also there is some stuff in there that is not worked out jet.
#include <SPI.h>                          //bluetooth
#include "Adafruit_BLE_UART.h"            //bluetooth

#include <SoftwareSerial.h>               //sounboard
#include "Adafruit_Soundboard.h"          //sounboard

#include <Wire.h>                         //servodriver
#include <Adafruit_PWMServoDriver.h>      //servodriver


//---------------------------Lights---------------------------------------------------------
// will store last time LED was updated
long previousMillisFading = 0;


// intervals
long interval1 = 50;           // interval at which to fade in (milliseconds)
long interval2 = 40;           // interval at which to fade out (milliseconds)


//led states
int ledblue = 0;                // tells if the blue leds are on or off
int ledred = 0;                // tells if the red leds are on or off
int fadeValue1 = 0;             // fadeValues used to set the blue LED
int fadeValue2 = 0;             // fadeValues used to set the Red LED

//---------------------------Bluetooth---------------------------------------------------------

// Connect CLK/MISO/MOSI to hardware SPI
// e.g. On UNO & compatible: CLK = 13, MISO = 12, MOSI = 11
#define ADAFRUITBLE_REQ 10    //DONT CHANGE THESE PINS, IT WILL FUCK UP YOUR ARDUINO MICRO/BLUETOOTH
#define ADAFRUITBLE_RDY 7     //DONT CHANGE THESE PINS, IT WILL FUCK UP YOUR ARDUINO MICRO/BLUETOOTH
#define ADAFRUITBLE_RST 9     //DONT CHANGE THESE PINS, IT WILL FUCK UP YOUR ARDUINO MICRO/BLUETOOTH

Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);



//---------------------------soundboard---------------------------------------------------------

// Choose any two pins that can be used with SoftwareSerial to RX & TX
#define SFX_TX 1
#define SFX_RX 0

// Connect to the RST pin on the Sound Board
#define SFX_RST 4


// we'll be using software serial
SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);

// pass the software serial to Adafruit_soundboard, the second
// argument is the debug port (not used really) and the third
// arg is the reset pin
Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);
// can also try hardware serial with
// Adafruit_Soundboard sfx = Adafruit_Soundboard(&Serial1, NULL, SFX_RST);

//---------------------------Servos---------------------------------------------------------

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you have!

//BACK
#define SERVOMIN  137 // this is the 'minimum' pulse length count of the back servo's (out of 4096) Depends on your servo, DONT CHANGE THESE FUCKERS!!!!
#define SERVOMAX  660 // this is the 'maximum' pulse length count of the back servo's (out of 4096) Depends on your servo, DONT CHANGE THESE FUCKERS!!!!

//TOP
#define SERVOMIN1  230 // this is the 'minimum' pulse length count of the faceplate servo's (out of 4096) Depends on your servo, DONT CHANGE THESE FUCKERS!!!!
#define SERVOMAX1  520 // this is the 'maximum' pulse length count of the faceplate servo's (out of 4096) Depends on your servo, DONT CHANGE THESE FUCKERS!!!!

long interval = 150;           // interval at which to fade in (milliseconds)
long previousMillisServo = 0;
int pulselen = 0;


//---------------------------Other---------------------------------------------------------

int counterintro = 0;
int counterservo = 0;
int countermotor = 0;


//-----------------------------------------------------------------------------------------

void setup(void)
{
  ss.begin(9600); // softwareserial at 9600 baud

  while (!Serial1); // Leonardo/Micro should wait for serial init
  BTLEserial.setDeviceName("MK42"); /* 7 characters max! */
  BTLEserial.begin();

  pwm.begin();
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz update
  yield();

  pinMode(A0, OUTPUT);  //motordriver
  pinMode(A1, OUTPUT);  //motordriver
  pinMode(A2, OUTPUT);  //motordriver
  pinMode(A3, OUTPUT);  //motordriver

  pinMode(5, OUTPUT);  //Blue Leds (PWM)
  pinMode(6, OUTPUT);  //Red Leds  (PWM)
  pinMode(12, OUTPUT);  //EL Wire




}

/**************************************************************************/
/*!
    Constantly checks for new events on the nRF8001
*/
/**************************************************************************/
aci_evt_opcode_t laststatus = ACI_EVT_DISCONNECTED;

void loop()
{

  // Tell the nRF8001 to do whatever it should be working on.
  BTLEserial.pollACI();

  // Ask what is our current status
  aci_evt_opcode_t status = BTLEserial.getState();


  if (status == ACI_EVT_DEVICE_STARTED) {
    counterintro = 0;
  }

  if (status == ACI_EVT_CONNECTED) {
    // OK while we still have something to read, get a character and print it out
    while (BTLEserial.available()) {
      char c = BTLEserial.read();

      if (c == '1') {
        Open();
      }


      if (c == '2') {
        Close();
      }


      if (c == '3') {
        normalmode();
      }

      if (c == '4') {
        battlemode();
      }

      if (c == '5') {
        off();
      }

    }

    String i/*ntro*/ = ("MK42 connected\n open = 1\n close = 2\n battle mode = 3\n normal mode = 4\n Off = 5\n");
    // We need to convert the line to bytes, no more than 20 at this time
    uint8_t sendbuffer[80];
    i.getBytes(sendbuffer, 80);
    char sendbuffersize = min(80, i.length());

    if (counterintro < 1) {
      // write the data
      BTLEserial.write(sendbuffer, sendbuffersize);
      counterintro++;
    }

  }

  if (status == ACI_EVT_DISCONNECTED) {
  }

}

//------------------------------------------------------------------------------------------------------------------
void Open () {


  if (millis() - previousMillisServo > interval) {
    previousMillisServo = millis();
    for (pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
      pwm.setPWM(servonum, 0, pulselen);
    }
  }



  digitalWrite(13, HIGH);


}
//------------------------------------------------------------------------------------------------------------------
void Close () {


  pwm.setPWM(15, 0, SERVOMIN1 );



  digitalWrite(13, LOW);


}
//------------------------------------------------------------------------------------------------------------------

void battlemode() {

  if (millis() - previousMillisFading > interval2) {

    previousMillisFading = millis();

    if ( fadeValue2 < 255 ) fadeValue2 += 5;
    if ( fadeValue1 <= 255 ) fadeValue1 -= 5;
  }


  analogWrite(6, fadeValue2);
  analogWrite(5, fadeValue1);

 // if (fadeValue2 == 255) ledred = 1;
//  if (fadeValue1 == 0) ledblue = 0;

}

If you guys could give me some pointers i’ll be happy

(sorry for my bad englisch)

I think you have a fundamental problem. Your code reads the data (one byte at a time). If that is e.g. ‘4’, you call battlemode(). Next battlemode() is never called again unless you send another ‘4’. So you need to send a whole bunch of ‘4’ to keep on calling battlemode().

Make the char c a static variable; also give it a decent name (mode in below) and move it to the beginning of loop().

void loop()
{
  // operation mode; initialised with 'off'
  static char mode = '5';

  ...
  ...

  if (status == ACI_EVT_CONNECTED)
  {
    // OK while we still have something to read, get a character and print it out
    if (BTLEserial.available())
    {
      mode = BTLEserial.read();
    }
  }

  if (mode == '1')
  {
    Open();
  }

  ...
  ...
}

Note the the while (BTLEserial.available()) is changed to an if (BTLEserial.available()).

And instead of using all those if statements, you might want to read up on e.g. the switch statement.

PS I used battlemode() just as an example, all your functions will be affected by the way you are reading your data.

Thanks sterretje for helping me out!

I changed the code but now i doesnt do anything… i think i may be in error.

here is my code:

  void loop()
{

  // operation mode; initialised with 'off'
 static char mode = '5';

  // Tell the nRF8001 to do whatever it should be working on.
  BTLEserial.pollACI();

  // Ask what is our current status
  aci_evt_opcode_t status = BTLEserial.getState();


  if (status == ACI_EVT_DEVICE_STARTED) {
    counterintro = 0;
  }

  if (status == ACI_EVT_CONNECTED)
  {
    // OK while we still have something to read, get a character and print it out
    if (BTLEserial.available())
    {
      mode = BTLEserial.read();
    }
  }

    switch (mode) {
      case 1:    
        Open ();
        break;
      case 2:    
        Close ();
        break;
      case 3:    
        battlemode();
        break;
      case 4:    
        normalmode();
        break;
      case 5:    
        off();
        break;
    }

  String i/*intro*/ = ("MK42 connected\n open = 1\n close = 2\n battle mode = 3\n normal mode = 4\n Off = 5\n");
  // We need to convert the line to bytes, no more than 20 at this time
  uint8_t sendbuffer[80];
  i.getBytes(sendbuffer, 80);
  char sendbuffersize = min(80, i.length());

  if (counterintro < 1) {
    // write the data
    BTLEserial.write(sendbuffer, sendbuffersize);
    counterintro++;
  }



  if (status == ACI_EVT_DISCONNECTED) {
  }

}

//------------------------------------------------------------------------------------------------------------------
void Open () {


  if (millis() - previousMillisServo > interval) {
    previousMillisServo = millis();
    for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
      pwm.setPWM(15, 0, pulselen);
    }
  }



  digitalWrite(13, HIGH);


}

I’m not entirely sure what the ‘static char’ thing does…
And i think that the switch statement isnt getting the ‘mode’ variable…

Ps are you by any change from the Netherlands?(sterretje)

static char mode = '5';

 switch (mode) {
      case 1:    
        Open ();
        break;

Here, for mode, you're using the ASCII character '5', but your switch/case later uses raw values.
Is that intentional?

A static variable is a local variable that does not forget its content when loop ends. So the next time loop is entered, it still remembers that you did send ‘1’.

And as AWOL implies

    switch (mode)
    {
      case '1':   <----- ascii character '1', not number 1
        ...
        ...
        break;
      case '2':   <----- ascii character '2', not number 2

Ah yes stupid mistake,‘mode’ is getting its values now.
However my servo is stil moving at the same speed and the leds dont fade in or out either. They just come halfway on and go out.

void loop()
{

  // operation mode; initialised with 'off'
  static char mode = '5';

  // Tell the nRF8001 to do whatever it should be working on.
  BTLEserial.pollACI();

  // Ask what is our current status
  aci_evt_opcode_t status = BTLEserial.getState();


  if (status == ACI_EVT_DEVICE_STARTED) {
    counterintro = 0;
  }

  if (status == ACI_EVT_CONNECTED)
  {
    // OK while we still have something to read, get a character and print it out
    if (BTLEserial.available())
    {
      mode = BTLEserial.read();
    }
  }

  switch (mode) {
    case '1':
      Open ();
      break;
    case '2':
      Close ();
      break;
    case '3':
      battlemode();
      break;
    case '4':
      normalmode();
      break;
    case '5':
      off();
      break;
  }

  String i/*intro*/ = ("MK42 connected\n open = 1\n close = 2\n battle mode = 3\n normal mode = 4\n Off = 5\n");
  // We need to convert the line to bytes, no more than 20 at this time
  uint8_t sendbuffer[80];
  i.getBytes(sendbuffer, 80);
  char sendbuffersize = min(80, i.length());

  if (counterintro < 1) {
    // write the data
    BTLEserial.write(sendbuffer, sendbuffersize);
    counterintro++;
  }



  if (status == ACI_EVT_DISCONNECTED) {
  }

}

//------------------------------------------------------------------------------------------------------------------
void Open () {


  if (millis() - previousMillisServo > interval) {
    previousMillisServo = millis();

    for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
      pwm.setPWM(15, 0, pulselen);
    }
  }



  digitalWrite(13, HIGH);


}
//------------------------------------------------------------------------------------------------------------------
void Close () {


  pwm.setPWM(15, 0, SERVOMIN1 );



  digitalWrite(13, LOW);


}
//------------------------------------------------------------------------------------------------------------------

void battlemode() {

  if (millis() - previousMillisFading > interval2) {

    previousMillisFading = millis();

    if ( fadeValue2 < 255 ) fadeValue2 += 5;
    if ( fadeValue1 <= 255 ) fadeValue1 -= 5;
  }


  analogWrite(6, fadeValue2);
  analogWrite(5, fadeValue1);

  if (fadeValue2 == 255) ledred = 1;
  if (fadeValue1 == 0) ledblue = 0;

}

//------------------------------------------------------------------------------------------------------------------
void normalmode() {

  if (millis() - previousMillisFading > interval2) {

    previousMillisFading = millis();

    if ( fadeValue2 <= 255 ) fadeValue2 -= 5;
    if ( fadeValue1 < 255 ) fadeValue1 += 5;
  }


  analogWrite(5, fadeValue2);
  analogWrite(6, fadeValue1);

  if (fadeValue1 == 255) ledblue = 1;
  if (fadeValue2 == 0) ledred = 0;


}

//------------------------------------------------------------------------------------------------------------------
void off() {

  if (millis() - previousMillisFading > interval2) {

    previousMillisFading = millis();

    if ( fadeValue1 > 0 ) fadeValue1 -= 5;
    if ( fadeValue2 > 0 ) fadeValue2 -= 5;
  }
  analogWrite(5, fadeValue1);
  analogWrite(6, fadeValue2);

  if (fadeValue1 == 0) ledblue = 0;
  if (fadeValue2 == 0) ledred = 0;

}

Thanks for all the help so far.

the leds dont fade in or out either.

Which timers are you using?

What do you mean by timers?

timer0 for millis (), and timer1 for the Adafruit_PWMServoDriver.h maybe…?

or do you mean the intervals?:

//---------------------------Lights---------------------------------------------------------
// will store last time LED was updated
long previousMillisFading = 0;


// intervals
long interval1 = 50;           // interval at which to fade in (milliseconds)
long interval2 = 40;           // interval at which to fade out (milliseconds)


//led states
int ledblue = 0;                // tells if the blue leds are on or off
int ledred = 0;                // tells if the red leds are on or off
int fadeValue1 = 0;             // fadeValues used to set the blue LED
int fadeValue2 = 0;             // fadeValues used to set the Red LED
void battlemode() {

  if (millis() - previousMillisFading > interval2) {

    previousMillisFading = millis();

    if ( fadeValue2 < 255 ) fadeValue2 += 5;
    if ( fadeValue1 <= 255 ) fadeValue1 -= 5;
  }


  analogWrite(6, fadeValue2);
  analogWrite(5, fadeValue1);

  if (fadeValue2 == 255) ledred = 1;
  if (fadeValue1 == 0) ledblue = 0;

}

hope this helps

Anybody?

It would be nice to update the title since Millis is not the name of a core library function.

bperrybap:
It would be nice to update the title since Millis is not the name of a core library function.

What do you mean by this?

M is not same letter as m
Put Millis() in your code and see if it works.

bperrybap:
M is not same letter as m
Put Millis() in your code and see if it works.

OK i see your point, changed the title. Still no closer to solving my problem though.

Mrmadjack:
However my servo is stil moving at the same speed

What do you mean by same speed. You do not seem to have any variable that influences the speed of the servo.

I don't know much about servos. But in the Open() function you move your servo every 150 ms from SERVOMIN to SERVOMAX as fast as the processor can do it; there is no speed.

Mrmadjack:
and the leds dont fade in or out either. They just come halfway on and go out.

Please explain what you expect your leds to do? Looking at normalmode(), pin 6 will only once go from 0 to 255. Pin 5 is possibly another story because it starts at 0 and next decrements (so -5, -10 etc) till it overflows (at -32768).

Lastly (I doubt its relevant now), who in his sane mind uses software serial on the hardware serial port?

// edit
Note
please post complete code after an update; I had to jump forward and backward between the opening post and reply #5 to find variables

sterretje:
What do you mean by same speed. You do not seem to have any variable that influences the speed of the servo.

By same speed i mean that the servo is stil moving from one point to antother at full speed, I want it to slow down.
I know you cant change the ‘speed’ the servo moves at, but you can however make the servo look like its moving slower by incrementing the servo at a certain speed.
I cant seem to get this working

sterretje:
Please explain what you expect your leds to do? Looking at normalmode(), pin 6 will only once go from 0 to 255. Pin 5 is possibly another story because it starts at 0 and next decrements (so -5, -10 etc) till it overflows (at -32768).

When you select ‘battlemode’ i want the led on pin 6 to fade on, and when you select ‘normalmode’ i want it to fade off.

sterretje:
Lastly (I doubt its relevant now), who in his sane mind uses software serial on the hardware serial port?

Maby this is a stupid quiestion, but why is this so terrible?

Here is the updated code

#include <SPI.h>                          //bluetooth
#include "Adafruit_BLE_UART.h"            //bluetooth

#include <SoftwareSerial.h>               //sounboard
#include "Adafruit_Soundboard.h"          //sounboard

#include <Wire.h>                         //servodriver
#include <Adafruit_PWMServoDriver.h>      //servodriver


//---------------------------Lights---------------------------------------------------------
// will store last time LED was updated
long previousMillisFading = 0;


// intervals
long interval1 = 50;           // interval at which to fade in (milliseconds)
long interval2 = 40;           // interval at which to fade out (milliseconds)


//led states
int ledblue = 0;                // tells if the blue leds are on or off
int ledred = 0;                // tells if the red leds are on or off
int fadeValue1 = 0;             // fadeValues used to set the blue LED
int fadeValue2 = 0;             // fadeValues used to set the Red LED

//---------------------------Bluetooth---------------------------------------------------------

// Connect CLK/MISO/MOSI to hardware SPI
// e.g. On UNO & compatible: CLK = 13, MISO = 12, MOSI = 11
#define ADAFRUITBLE_REQ 10    //DONT CHANGE THESE PINS, IT WILL FUCK UP YOUR ARDUINO MICRO/BLUETOOTH
#define ADAFRUITBLE_RDY 7     //DONT CHANGE THESE PINS, IT WILL FUCK UP YOUR ARDUINO MICRO/BLUETOOTH
#define ADAFRUITBLE_RST 9     //DONT CHANGE THESE PINS, IT WILL FUCK UP YOUR ARDUINO MICRO/BLUETOOTH

Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);



//---------------------------soundboard---------------------------------------------------------

// Choose any two pins that can be used with SoftwareSerial to RX & TX
#define SFX_TX 1
#define SFX_RX 0

// Connect to the RST pin on the Sound Board
#define SFX_RST 4


// we'll be using software serial
SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);

// pass the software serial to Adafruit_soundboard, the second
// argument is the debug port (not used really) and the third
// arg is the reset pin
Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);
// can also try hardware serial with
// Adafruit_Soundboard sfx = Adafruit_Soundboard(&Serial1, NULL, SFX_RST);

//---------------------------Servos---------------------------------------------------------

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you have!

//BACK
#define SERVOMIN  137 // this is the 'minimum' pulse length count of the back servo's (out of 4096) Depends on your servo, DONT CHANGE THESE FUCKERS!!!!
#define SERVOMAX  660 // this is the 'maximum' pulse length count of the back servo's (out of 4096) Depends on your servo, DONT CHANGE THESE FUCKERS!!!!

//TOP
#define SERVOMIN1  230 // this is the 'minimum' pulse length count of the faceplate servo's (out of 4096) Depends on your servo, DONT CHANGE THESE FUCKERS!!!!
#define SERVOMAX1  520 // this is the 'maximum' pulse length count of the faceplate servo's (out of 4096) Depends on your servo, DONT CHANGE THESE FUCKERS!!!!

long interval = 30;
long previousMillisServo = 0;
long pulselen = 0;


//---------------------------Other---------------------------------------------------------

int counterintro = 0;
int counterservo = 0;
int countermotor = 0;


//-----------------------------------------------------------------------------------------

void setup(void)
{
  ss.begin(9600); // softwareserial at 9600 baud

  while (!Serial1); // Leonardo/Micro should wait for serial init
  BTLEserial.setDeviceName("MK42"); /* 7 characters max! */
  BTLEserial.begin();

  pwm.begin();
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz update
  yield();

  pinMode(A0, OUTPUT);  //motordriver
  pinMode(A1, OUTPUT);  //motordriver
  pinMode(A2, OUTPUT);  //motordriver
  pinMode(A3, OUTPUT);  //motordriver

  pinMode(5, OUTPUT);  //Blue Leds (PWM)
  pinMode(6, OUTPUT);  //Red Leds  (PWM)
  pinMode(12, OUTPUT);  //EL Wire




}

/**************************************************************************/
/*!
    Constantly checks for new events on the nRF8001
*/
/**************************************************************************/
aci_evt_opcode_t laststatus = ACI_EVT_DISCONNECTED;

void loop()
{

  // operation mode; initialised with 'off'
  static char mode = '5';

  // Tell the nRF8001 to do whatever it should be working on.
  BTLEserial.pollACI();

  // Ask what is our current status
  aci_evt_opcode_t status = BTLEserial.getState();


  if (status == ACI_EVT_DEVICE_STARTED) {
    counterintro = 0;
  }

  if (status == ACI_EVT_CONNECTED)
  {
    // OK while we still have something to read, get a character and print it out
    if (BTLEserial.available())
    {
      mode = BTLEserial.read();
    }
  }

  switch (mode) {
    case '1':
      Open ();
      break;
    case '2':
      Close ();
      break;
    case '3':
      battlemode();
      break;
    case '4':
      normalmode();
      break;
    case '5':
      off();
      break;
  }

  String i/*intro*/ = ("MK42 connected\n open = 1\n close = 2\n battle mode = 3\n normal mode = 4\n Off = 5\n");
  // We need to convert the line to bytes, no more than 20 at this time
  uint8_t sendbuffer[80];
  i.getBytes(sendbuffer, 80);
  char sendbuffersize = min(80, i.length());

  if (counterintro < 1) {
    // write the data
    BTLEserial.write(sendbuffer, sendbuffersize);
    counterintro++;
  }



  if (status == ACI_EVT_DISCONNECTED) {
  }

}

//------------------------------------------------------------------------------------------------------------------
void Open () {


  if (millis() - previousMillisServo > interval) {
    previousMillisServo = millis();

    if (pulselen < SERVOMAX) {
      pulselen++;

    }
  }

  pwm.setPWM(15, 0, pulselen);

  digitalWrite(13, HIGH);


}
//------------------------------------------------------------------------------------------------------------------
void Close () {


  pwm.setPWM(15, 0, SERVOMIN1 );



  digitalWrite(13, LOW);


}
//------------------------------------------------------------------------------------------------------------------

void battlemode() {

  if (millis() - previousMillisFading > interval2) {

    previousMillisFading = millis();

    if ( fadeValue2 < 255 ) fadeValue2 += 5;
  }


  analogWrite(6, fadeValue2);


  if (fadeValue2 == 255) ledred = 1;


}

//------------------------------------------------------------------------------------------------------------------
void normalmode() {

  if (millis() - previousMillisFading > interval2) {

    previousMillisFading = millis();

    if ( fadeValue1 >0 ) fadeValue1 -= 5;
  }



  analogWrite(6, fadeValue1);

  if (fadeValue1 == 255) ledblue = 1;



}



}

//Edit

I’m using an arduino micro, adafruit nrf8001 bluetooth board, adafruit sound fx board and an adafruit 16 channel pmw servo driver board.

Mrmadjack:
Lastly (I doubt its relevant now), who in his sane mind uses software serial on the hardware serial port?
Maby this is a stupid quiestion, but why is this so terrible?

Why would you emulate a retarded version of an existing hardware feature?

Software Serial is half-duplex, sends with software timing (blocking) and is limited to low baudrates.

Whandall:
Why would you emulate a retarded version of an exiisting hardware feature?

Software Serial is half-duplex, sends with software timing (blocking) and is limited to low baudrates.

Ok, i thought i needed it for the soundboard, i followed the examples on the adafruit website.
How do i go about using the regular serial for my soundboard?

//Edit

I'm using an arduino micro, adafruit nrf8001 bluetooth board, adafruit sound fx board and an adafruit 16 channel pmw servo driver board.

Mrmadjack:
How do i go about using the regular serial for my soundboard?

Connect to rx and tx pins of the Micro and communicate via Serial1.

Whandall:
Connect to rx and tx pins of the Micro and communicate via Serial1.

Changed the code accordingly. I think…

Does anybody have any idea why my servo’s wont move slower and my leds wont fade?

#include <SPI.h>                          //bluetooth
#include "Adafruit_BLE_UART.h"            //bluetooth

#include <SoftwareSerial.h>               //sounboard
#include "Adafruit_Soundboard.h"          //sounboard

#include <Wire.h>                         //servodriver
#include <Adafruit_PWMServoDriver.h>      //servodriver


//---------------------------Lights---------------------------------------------------------
// will store last time LED was updated
long previousMillisFading = 0;


// intervals
long interval1 = 50;           // interval at which to fade in (milliseconds)
long interval2 = 40;           // interval at which to fade out (milliseconds)


//led states
int ledblue = 0;                // tells if the blue leds are on or off
int ledred = 0;                // tells if the red leds are on or off
int fadeValue1 = 0;             // fadeValues used to set the blue LED
int fadeValue2 = 0;             // fadeValues used to set the Red LED

//---------------------------Bluetooth---------------------------------------------------------

// Connect CLK/MISO/MOSI to hardware SPI
// e.g. On UNO & compatible: CLK = 13, MISO = 12, MOSI = 11
#define ADAFRUITBLE_REQ 10    //DONT CHANGE THESE PINS, IT WILL FUCK UP YOUR ARDUINO MICRO/BLUETOOTH
#define ADAFRUITBLE_RDY 7     //DONT CHANGE THESE PINS, IT WILL FUCK UP YOUR ARDUINO MICRO/BLUETOOTH
#define ADAFRUITBLE_RST 9     //DONT CHANGE THESE PINS, IT WILL FUCK UP YOUR ARDUINO MICRO/BLUETOOTH

Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);



//---------------------------soundboard---------------------------------------------------------


// Connect to the RST pin on the Sound Board
#define SFX_RST 4


// can also try hardware serial with
Adafruit_Soundboard sfx = Adafruit_Soundboard(&Serial1, NULL, SFX_RST); //TX 1 RX 0

//---------------------------Servos---------------------------------------------------------

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you have!

//BACK
#define SERVOMIN  137 // this is the 'minimum' pulse length count of the back servo's (out of 4096) Depends on your servo, DONT CHANGE THESE FUCKERS!!!!
#define SERVOMAX  660 // this is the 'maximum' pulse length count of the back servo's (out of 4096) Depends on your servo, DONT CHANGE THESE FUCKERS!!!!

//TOP
#define SERVOMIN1  230 // this is the 'minimum' pulse length count of the faceplate servo's (out of 4096) Depends on your servo, DONT CHANGE THESE FUCKERS!!!!
#define SERVOMAX1  520 // this is the 'maximum' pulse length count of the faceplate servo's (out of 4096) Depends on your servo, DONT CHANGE THESE FUCKERS!!!!

long interval = 60;
long previousMillisServo = 0;
long pulselen = 0;


//---------------------------Other---------------------------------------------------------

int counterintro = 0;
int counterservo = 0;
int countermotor = 0;


//-----------------------------------------------------------------------------------------

void setup(void)
{
  Serial1.begin(115200); 

  while (!Serial1); // Leonardo/Micro should wait for serial init
  BTLEserial.setDeviceName("MK42"); /* 7 characters max! */
  BTLEserial.begin();

  pwm.begin();
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz update
  yield();

  pinMode(A0, OUTPUT);  //motordriver
  pinMode(A1, OUTPUT);  //motordriver
  pinMode(A2, OUTPUT);  //motordriver
  pinMode(A3, OUTPUT);  //motordriver

  pinMode(5, OUTPUT);  //Blue Leds (PWM)
  pinMode(6, OUTPUT);  //Red Leds  (PWM)
  pinMode(12, OUTPUT);  //EL Wire




}

/**************************************************************************/
/*!
    Constantly checks for new events on the nRF8001
*/
/**************************************************************************/
aci_evt_opcode_t laststatus = ACI_EVT_DISCONNECTED;

void loop()
{

  // operation mode; initialised with 'off'
  static char mode = '5';

  // Tell the nRF8001 to do whatever it should be working on.
  BTLEserial.pollACI();

  // Ask what is our current status
  aci_evt_opcode_t status = BTLEserial.getState();


  if (status == ACI_EVT_DEVICE_STARTED) {
    counterintro = 0;
  }

  if (status == ACI_EVT_CONNECTED)
  {
    // OK while we still have something to read, get a character and print it out
    if (BTLEserial.available())
    {
      mode = BTLEserial.read();
    }


    switch (mode) {
      case '1':
        Open ();
        break;
      case '2':
        Close ();
        break;
      case '3':
        battlemode();
        break;
      case '4':
        normalmode();
        break;
      case '5':
        off();
        break;
    }

    String i/*intro*/ = ("MK42 connected\n open = 1\n close = 2\n battle mode = 3\n normal mode = 4\n Off = 5\n");
    // We need to convert the line to bytes, no more than 20 at this time
    uint8_t sendbuffer[80];
    i.getBytes(sendbuffer, 80);
    char sendbuffersize = min(80, i.length());

    if (counterintro < 1) {
      // write the data
      BTLEserial.write(sendbuffer, sendbuffersize);
      counterintro++;
    }

  }

  if (status == ACI_EVT_DISCONNECTED) {
    counterintro = 0;
  }

}

//------------------------------------------------------------------------------------------------------------------
void Open () {


  if (millis() - previousMillisServo > interval) {
    previousMillisServo = millis();

    if (pulselen < SERVOMAX) {
      pulselen++;

    }
  }

  pwm.setPWM(15, 0, pulselen);

  digitalWrite(13, HIGH);


}
//------------------------------------------------------------------------------------------------------------------
void Close () {


  pwm.setPWM(15, 0, SERVOMIN1 );



  digitalWrite(13, LOW);


}
//------------------------------------------------------------------------------------------------------------------

void battlemode() {

  if (millis() - previousMillisFading > interval2) {

    previousMillisFading = millis();

    if ( fadeValue2 < 255 ) fadeValue2 += 5;
  }


  analogWrite(6, fadeValue2);


  if (fadeValue2 == 255) ledred = 1;


}

//------------------------------------------------------------------------------------------------------------------
void normalmode() {

  if (millis() - previousMillisFading > interval2) {

    previousMillisFading = millis();

    if ( fadeValue1 > 0 ) fadeValue1 -= 5;
  }



  analogWrite(6, fadeValue1);

  if (fadeValue1 == 255) ledblue = 1;



}

I’m using an arduino micro, adafruit nrf8001 bluetooth board, adafruit sound fx board and an adafruit 16 channel pmw servo driver board.

I assume that the value of pulselen determines how fast the servo moves. Once it reaches SERVOMAX how will it ever have any other value ?