Updated for latest PlatformIO

This commit is contained in:
2023-10-28 00:16:32 +02:00
parent 406cb2a70d
commit 6109f2bf92
2 changed files with 78 additions and 66 deletions
+23 -15
View File
@@ -1,11 +1,11 @@
/*************************************
* Kerstboomshield voor Arduino
* arduino-kerstboomshield
* Author: Michel Bats
* Website: www.batssoft.nl
* Version: 1.0.0
* Revision: 20141216
*************************************/
#include <Arduino.h>
// Bepalingen
int ledPin[] = {
6, 9, 10, 11}; // Uitgangen met PWM-mogelijkheden
@@ -21,31 +21,39 @@ int delayPot = A5; // Ingang potmeter
// Aanmaken benodigde variabelen
int temp0;
void setup() {
void setup()
{
// Loop om door het aantal volgens ledCount te gaan
for (int i=0; i <= (ledCount-1); i++){
for (int i = 0; i <= (ledCount - 1); i++)
{
// eerst initialisatie van de PWM-puls op de uitgangen
analogWrite(ledPin[i], currentLedPwm[i]);
}
}
void loop() {
void loop()
{
// Uitlezen potmeter voor instelling vertraging (delay())
int delayPotValue = analogRead(delayPot);
// Gegevens potmeter omzetten naar 1 t/m 25ms voor de delay()
int delayPotValueMap = map(delayPotValue, 0, 1023, 1, 25);
// Loop om door het aantal volgens ledCount te gaan
for (int i=0; i <= (ledCount-1); i++){
for (int i = 0; i <= (ledCount - 1); i++)
{
// Controleren of randomLed 0 of kleiner is zodat deze een nieuwe waarde kan krijgen (random() tussen max in de nieuwe richting en de helft van max en huidige waarde)
if (randomLed[i] <= 0){
if (randomLed[i] <= 0)
{
// Waarde countLedUp omdraaien
countLedUp[i] = map(countLedUp[i], 1, 0, 0, 1);
// Controleren of countLedUp nu 1 of 0 is.
if (countLedUp[i] == 1) {
if (countLedUp[i] == 1)
{
// In geval van een 1: temp0 vullen met de maximaal aantal stappen tussen currentLedPwm en de maximale PWM-puls-waarde (255).
temp0 = 255 - currentLedPwm[i];
} else {
}
else
{
// In geval van een 0: temp0 vullen met currentLedPwm aangezien dat de stappen zijn tot de minimale waarde voor een PWM-puls (0).
temp0 = currentLedPwm[i];
}
@@ -54,10 +62,13 @@ void loop() {
}
// Controleren of de LED(-array) feller of zwakker moet gaan branden op basis van countLedUp
if (countLedUp[i] == 1) {
if (countLedUp[i] == 1)
{
// currentLedPwm met 1 ophogen.
currentLedPwm[i]++;
} else {
}
else
{
// currentLedPwm met 1 verlagen.
currentLedPwm[i]--;
}
@@ -72,6 +83,3 @@ void loop() {
// Pauze inlassen met het aantal ms volgens delayPotValueMap
delay(delayPotValueMap);
}
@@ -1,12 +1,11 @@
/*************************************
* Kerstboomshield voor Arduino
* arduino-kerstboomshield-visualpwm
* Author: Michel Bats
* Website: www.batssoft.nl
* Version: 1.0.0
* Revision: 20141216
*************************************/
// Bibliotheken
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
@@ -36,36 +35,43 @@ int currentLedPwmDisp;
// Initialisatie Adafruit_SSD1306
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
void setup()
{
// Start Display
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR, HEX);
display.clearDisplay();
// Loop om door het aantal volgens ledCount te gaan
for (int i=0; i <= (ledCount-1); i++){
for (int i = 0; i <= (ledCount - 1); i++)
{
// eerst initialisatie van de PWM-puls op de uitgangen
analogWrite(ledPin[i], currentLedPwm[i]);
}
}
void loop() {
void loop()
{
// Uitlezen potmeter voor instelling vertraging (delay())
int delayPotValue = analogRead(delayPot);
// Gegevens potmeter omzetten naar 1 t/m 25ms voor de delay()
int delayPotValueMap = map(delayPotValue, 0, 1023, 1, 25);
// Loop om door het aantal volgens ledCount te gaan
for (int i=0; i <= (ledCount-1); i++){
for (int i = 0; i <= (ledCount - 1); i++)
{
// Controleren of randomLed 0 of kleiner is zodat deze een nieuwe waarde kan krijgen (random() tussen max in de nieuwe richting en de helft van max en huidige waarde)
if (randomLed[i] <= 0){
if (randomLed[i] <= 0)
{
// Waarde countLedUp omdraaien
countLedUp[i] = map(countLedUp[i], 1, 0, 0, 1);
// Controleren of countLedUp nu 1 of 0 is.
if (countLedUp[i] == 1) {
if (countLedUp[i] == 1)
{
// In geval van een 1: temp0 vullen met de maximaal aantal stappen tussen currentLedPwm en de maximale PWM-puls-waarde (255).
temp0 = 255 - currentLedPwm[i];
}
else {
else
{
// In geval van een 0: temp0 vullen met currentLedPwm aangezien dat de stappen zijn tot de minimale waarde voor een PWM-puls (0).
temp0 = currentLedPwm[i];
}
@@ -74,11 +80,13 @@ void loop() {
}
// Controleren of de LED(-array) feller of zwakker moet gaan branden op basis van countLedUp
if (countLedUp[i] == 1) {
if (countLedUp[i] == 1)
{
// currentLedPwm met 1 ophogen.
currentLedPwm[i]++;
}
else {
else
{
// currentLedPwm met 1 verlagen.
currentLedPwm[i]--;
}
@@ -106,7 +114,3 @@ void loop() {
// Pauze inlassen met het aantal ms volgens delayPotValueMap
delay(1);
}