Go Down

Topic: Two Methods At Once (Read 4023 times) previous topic - next topic

SimpleSDK

Just changed what needed to be changed and sure enough, it worked! Since your code allows me to vary the speed between the cheek and the chin, I'll most likely be using your code throughout my project and editing it for the rainbow too. When I receive my boards and hook everything up, I'll post a video and show how it looks.

Thanks so much!

johnwasser


John the only problem I see is that when I add the rainbow lights, they will go the same speed as the cheek and chin which is not what I want, but for now I'm using it.


Ah...  You didn't mention another set of lights going at a different speed.

Do the speeds have a common factor?  For example you could step the chin LEDs at half speed (600 milliseconds) by doubling each entry:
Code: [Select]

const int ChinPins[] = {10,10,11,11,12,12,13,13};

Each light would stay on for two consecutive periods giving the appearance of a slower scan.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp
See who has no social life: https://forum.arduino.cc/index.php?action=stats :)

SimpleSDK

It seems easy how you did it in that line, but I am pretty convinced to use the other code I currently have on the Arduino because it seems much more advanced to me. I'm a beginner sort of in Arduino, so I'm just going with what I've got. However, like I said, when I receive my boards, I will use both yours and scswift's code and see which is better.

johnwasser

I put in some changes so that not only can the animation rate be adjusted per group but also for individual lights within the group.  For each light you specify how many milliseconds it will stay lit before going on to the next.  Using the two current groups as an example it should be easy to add other groups.

Code: [Select]

const int CheekPins[] = {
  3,4,5,6,7,8,9,8,7,6,5,4};  // gives forward and back
const int CHEEK_COUNT = sizeof CheekPins / sizeof (int);
const int CheekIntervals[] = {
  300, 300, 300, 300, 300, 300,
  300, 300, 300, 300, 300, 300}  ;  // Milliseconds
unsigned long CheekTime = millis();
int CheekStep = 0;

const int ChinPins[] = {10,11,12,13};
const int CHIN_COUNT = sizeof ChinPins / sizeof (int);
const int ChinIntervals[] = {300, 300, 300, 300} ;  // Milliseconds
unsigned long ChinTime = millis();
int ChinStep = 0;

void setup()
{
  int i;
  /* Cheek LED's */
  for (i=0; i< CHEEK_COUNT; i++)
    pinMode(CheekPins[i], OUTPUT);  // Yes, it's OK to set the pinMode twice on some pins

  /* Chin LED's */
  for (i=0; i< CHIN_COUNT; i++)
    pinMode(ChinPins[i], OUTPUT);
}

void loop()
{
  // Do the cheek animation
  if ((millis() - CheekTime) > CheekIntervals[CheekStep])
  {
    CheekTime = millis();
    digitalWrite(CheekPins[CheekStep], LOW);
    CheekStep = (CheekStep+1) % CHEEK_COUNT;
    digitalWrite(CheekPins[CheekStep], HIGH);
  }

  // Do the chin animation
  if ((millis() - ChinTime) > ChinIntervals[ChinStep])
  {
    ChinTime = millis();
    digitalWrite(ChinPins[ChinStep], LOW);
    ChinStep = (ChinStep+1) % CHIN_COUNT;
    digitalWrite(ChinPins[ChinStep], HIGH);
  }
}

Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp
See who has no social life: https://forum.arduino.cc/index.php?action=stats :)

SimpleSDK

Your new code works very well too now! Just comes down until I have every board made. Thanks! :)

Go Up