Hey all,
I was wondering if anyone can help.....
I am using a thermocouple to act as an actuator to turn on a series of lights. When i breathe on it, it turns on the LEDs (very nearly) simultaneously, which is desired. When my timer reaches a certain point and the temp falls below a point, the LEDs turn off sequentially (that is, 1 then 2 then 3 then 4.....etc). What i'm trying to figure out is how to make them turn off non-sequentially (That is, turn off LED 2 then 7 then 4 then 1.....etc.) Ideally, this new sequence would be random each time.
I seem to remember seeing a post where someone randomized their array to do this, but i cant find it, and also, Im an art student, not a programmer, so i tend to stumble through even the simplest solutions.
Any help is greatly appreciated! Thank in advance!
#include <SPI.h>
#include "Adafruit_MAX31855.h"
#define MAXDO 3
#define MAXCS 4
#define MAXCLK 5
int pinArray[] = {7, 8, 9, 10, 11, 12, 13};
int count = 0;
//List of random times for each pendulum to run
int randomTimes[] = {random(4600, 8400), random(4600, 8400), random(4600, 8400), random(4600, 8400), random(4600, 8400), random(4600, 8400), random(4600, 8400)};
int timer = 0; //tracks current loop
Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);
#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
#define Serial SerialUSB
#endif
void setup() {
for (count = 0; count < 7; count++) {
pinMode(pinArray[count], OUTPUT);
}
#ifndef ESP8266
while (!Serial); // will pause Zero, Leonardo, etc until serial console opens
#endif
Serial.begin(9600);
Serial.println("MAX31855 test");
// wait for MAX chip to stabilize
delay(500);
}
void loop() {
// basic readout test, just print the current temp
Serial.print("Internal Temp = ");
Serial.println(thermocouple.readInternal());
double c = thermocouple.readCelsius();
if (isnan(c)) {
Serial.println("Something wrong with thermocouple!");
} else {
Serial.print("C = ");
Serial.println(c);
}
//////////////////////////////////////////
if (c >= 30 && timer < randomTimes[count]) { //turn pendulums on
timer = 10000; //increment timer
for (count = 0; count < 7; count++) {
//if time set for that pendulum is less than curren time
digitalWrite(pinArray[count], HIGH); //turn on this pendulum
}
}
if (c < 30 && timer > randomTimes[count]) { //turn pendulums off
for (count=0;count<7;count++) {
digitalWrite(pinArray[count], LOW);
timer = 0; //reset timer
delay (randomTimes[count]);
}
delay (500);
}