how do I combine
the code found at
and the code found at
https://create.arduino.cc/projecthub/LiLShReDdeR/charlieplexing-with-arduino-5b4ade
the first base code is
// These variables store the flash pattern
// and the current state of the LED
int ledPin1 = 12; // the number of the LED pin
int ledState1 = LOW; // ledState used to set the LED
unsigned long previousMillis1 = 0; // will store last time LED was updated
long OnTime1 = 250; // milliseconds of on-time
long OffTime1 = 750; // milliseconds of off-time
int ledPin2 = 13; // the number of the LED pin
int ledState2 = LOW; // ledState used to set the LED
unsigned long previousMillis2 = 0; // will store last time LED was updated
long OnTime2 = 330; // milliseconds of on-time
long OffTime2 = 400; // milliseconds of off-time
void setup()
{
// set the digital pin as output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}
void loop()
{
// check to see if it's time to change the state of the LED
unsigned long currentMillis = millis();
if((ledState1 == HIGH) && (currentMillis - previousMillis1 >= OnTime1))
{
ledState1 = LOW; // Turn it off
previousMillis1 = currentMillis; // Remember the time
digitalWrite(ledPin1, ledState1); // Update the actual LED
}
else if ((ledState1 == LOW) && (currentMillis - previousMillis1 >= OffTime1))
{
ledState1 = HIGH; // turn it on
previousMillis1 = currentMillis; // Remember the time
digitalWrite(ledPin1, ledState1); // Update the actual LED
}
if((ledState2 == HIGH) && (currentMillis - previousMillis2 >= OnTime2))
{
ledState2 = LOW; // Turn it off
previousMillis2 = currentMillis; // Remember the time
digitalWrite(ledPin2, ledState2); // Update the actual LED
}
else if ((ledState2 == LOW) && (currentMillis - previousMillis2 >= OffTime2))
{
ledState2 = HIGH; // turn it on
previousMillis2 = currentMillis; // Remember the time
digitalWrite(ledPin2, ledState2); // Update the actual LED
}
}
the second base code is
int A = 7;
int B = 8;
int C = 9;
void setup()
{
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
}
/*
- Turn on the given LED
- @paramledNum LED to turn on (1..6)
*/
void setLED(int ledNum)
{
if(ledNum == 1)
{
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, INPUT);
digitalWrite(A, HIGH);
digitalWrite(B, LOW);
}
if(ledNum == 2)
{
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, INPUT);
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
}
if(ledNum == 3)
{
pinMode(A, INPUT);
pinMode(B, OUTPUT); // changed to input to trigger tri state.
pinMode(C, OUTPUT);
digitalWrite(B, HIGH);
digitalWrite(C, LOW);
}
if(ledNum == 4)
{
pinMode(A, INPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
digitalWrite(B, LOW);
digitalWrite(C, HIGH);
}
if(ledNum == 5)
{
pinMode(A, OUTPUT);
pinMode(B, INPUT);
pinMode(C, OUTPUT);
digitalWrite(A, HIGH);
digitalWrite(C, LOW);
}
if(ledNum == 6)
{
pinMode(A, OUTPUT);
pinMode(B, INPUT);
pinMode(C, OUTPUT);
digitalWrite(A, LOW);
digitalWrite(C,HIGH);
}
}
void loop()
{
for(;
{
setLED(1);
delay(1000);
setLED(2);
delay(200);
setLED(3);
delay(200);
setLED(4);
delay(200);
setLED(5);
delay(200);
setLED(6);
delay(200);
}
}