While I continue to prepare for my big project, I still have a few more things to test. Namely, I need to test the digital outputs to make sure that I understand how to use them. So, I wrote this little ditty to get the job done. Note that I just tacked this onto the end of my previous work.
#include <bluefruit.h>
int brightness = 0; // how bright the LED is
int fadeAmount = 10; // how many points to fade the LED by
int highOrNot = 1; // Just a number.void setup() {
pinMode(19, OUTPUT); //19 is blue LED, 17 is red LED.
pinMode(11, OUTPUT); //19 is blue LED, 17 is red LED.
// initialize serial communication at 9600 bits per second:
Serial.begin(2400);
digitalWrite(11, HIGH);
}void loop() {
analogWrite(19, brightness);// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 50) {
fadeAmount = -fadeAmount;
}
// wait for 500 milliseconds to see the dimming effect
delay(1000);
// To print the brightness // Serial.println(brightness);// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 – 1023) to a voltage (0 – 3.6V):
float voltage = sensorValue * (3.6 / 1023.0);
// print out the value you read:
if (voltage >= 0.2) {
Serial.print(“Pin A01: “);Serial.println(voltage);
}if (highOrNot > 0) {
digitalWrite(11, HIGH);
highOrNot = highOrNot -1;
} else {
digitalWrite(11, LOW);
highOrNot = highOrNot +2;
}
}
With the multi-meter hooked up to pins 11 and pin ground on the Bluefruit, I was able to see my program in action. So, during the loop of the program, it checks the number “highOrNot” (sounds like a bad drug joke). If the number is greater than 0, then make pin 11 a HIGH output, or in this case, 3.3 vdc. Also, if it is greater than 0, minus one from the number for the next loop.
As the loop runs again, the number will eventually drop to 0. When it does, add 2 to the number and make pin 11 LOW, or 0 vdc. This turns off the digital pin. Notice that I also increased the loop delay to every second, rather than 1/2 seconds. So, my multi-meter was dancing with 3.3 vdc for two seconds, then 0 for 1 second, on a continuous loop. Spiffy, huh?
Linux – keep it simple.