Improvement
1. Modified the final code to light 2 or more bulbs together
As something approaches to the sensor more and more, the more light bulbs are lightened, and through this, the colors of each bulb can be mixed(which was my starting point of this project).
2. Made a dot matrix work
but still need to put those things together.
Here’s the edited code
void output_check() { // Function will fire the triac at the proper time for( j=0; j<5; j++ ) { // Loop this function for each one of the outputs if(zero_cross[j]) { // First check to make sure the zero-cross has happened else do nothing if(i[j] >= output[j] && ACenable[j]) { // Check and see if i has accumilated to the dimming value we want if(angle>0 && angle<72){ digitalWrite(AC[0], HIGH); // Fire the Triac mid-phase delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[0], LOW); // Turn off the Triac gate (Triac will not turn off until next zero cross) i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; // Reset the zero cross detection if(Tvect > 4500){ digitalWrite(AC[1], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[1], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; // Reset the zero cross detection if(Tvect > 5000){ digitalWrite(AC[2], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[2], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; if(Tvect > 5500){ digitalWrite(AC[3], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[3], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; if(Tvect > 6000){ digitalWrite(AC[4], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[4], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; } } } } } else { i[j]++; } if(angle>=72 && angle<144){ digitalWrite(AC[1], HIGH); // Fire the Triac mid-phase delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[1], LOW); // Turn off the Triac gate (Triac will not turn off until next zero cross) i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; // Reset the zero cross detection if(Tvect > 4500){ digitalWrite(AC[2], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[2], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; // Reset the zero cross detection if(Tvect > 5000){ digitalWrite(AC[3], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[3], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; if(Tvect > 5500){ digitalWrite(AC[4], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[4], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; if(Tvect > 6000){ digitalWrite(AC[0], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[0], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; } } } } }else { i[j]++; } if(angle>=144 && angle<216){ digitalWrite(AC[2], HIGH); // Fire the Triac mid-phase delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[2], LOW); // Turn off the Triac gate (Triac will not turn off until next zero cross) i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; // Reset the zero cross detection if(Tvect > 4500){ digitalWrite(AC[1], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[1], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; // Reset the zero cross detection if(Tvect > 5000){ digitalWrite(AC[0], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[0], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; if(Tvect > 5500){ digitalWrite(AC[3], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[3], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; if(Tvect > 6000){ digitalWrite(AC[4], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[4], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; } } } } }else { i[j]++; } // if nothing is done incriment th counter if(angle>=216 && angle<288){ digitalWrite(AC[3], HIGH); // Fire the Triac mid-phase delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[3], LOW); // Turn off the Triac gate (Triac will not turn off until next zero cross) i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; // Reset the zero cross detection if(Tvect > 4500){ digitalWrite(AC[1], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[1], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; // Reset the zero cross detection if(Tvect > 5000){ digitalWrite(AC[2], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[2], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; if(Tvect > 5500){ digitalWrite(AC[0], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[0], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; if(Tvect > 6000){ digitalWrite(AC[4], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[4], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; } } } } }else { i[j]++; } if(angle>=288 && angle<360){ digitalWrite(AC[4], HIGH); // Fire the Triac mid-phase delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[4], LOW); // Turn off the Triac gate (Triac will not turn off until next zero cross) i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; // Reset the zero cross detection if(Tvect > 4500){ digitalWrite(AC[1], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[1], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; // Reset the zero cross detection if(Tvect > 5000){ digitalWrite(AC[2], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[2], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; if(Tvect > 5500){ digitalWrite(AC[3], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[3], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; if(Tvect > 6000){ digitalWrite(AC[0], HIGH); delayMicroseconds(15); // Pause briefly to ensure the triac turned on digitalWrite(AC[0], LOW); i[j]=0; // If we fired the triac, reset the counters zero_cross[j] = 0; } } } } } }else { i[j]++; } // if nothing is done incriment th counter } // End zero_cross check } // End each loop } // End output_check function








