The problem is that I'm not happy with the output and I'm just having some trouble wrapping my brain around the problem in such a way that I may come up with a good solution.
Basically the idea is for this to illuminate 32 LEDs in a sequence based on hard drive activity. Before someone says it, yes I realize the arduino is somewhat overkill for this basic part of the project but I also have other plans that involve serial communication with the PC in a possible future version. For now, this is all it does.
The reason I am not happy with the output is basically it does not really move from flickering the first LED in the display unless there is major drive activity like copying a file. Even watching a HD movie only flickers maybe the first two or three if I'm lucky. I'm sure there is a better way to achieve a better display but I'm just not seeing it.
Below I have included my sketch. I've commented everything I believe so you will know whats going on at each point...
It is probably not perfect but it works
Code: Select all
// Include Wire.h for I2C to the MCP23017
#include <Wire.h>
// Include Adafruit library for MCP23017
#include "Adafruit_MCP23017.h"
// Make object array for MCP23017's
Adafruit_MCP23017 mcpArray[2];
// HDD activity line
int hddPin = 3;
// Start the LED scale at 100%
int activity = 32;
void setup() {
// Initialize the MCP23017's in the array
mcpArray[0].begin(0);
mcpArray[1].begin(1);
// Start serial for debugging
Serial.begin(9600);
// Set pinMode for ATmega328
pinMode(hddPin, INPUT);
pinMode(13, OUTPUT);
// Set pinMode and illuminate LED for each MCP23017
for (int thisPin = 0; thisPin < 17; thisPin++) {
mcpArray[0].pinMode(thisPin, OUTPUT);
mcpArray[0].digitalWrite((thisPin & 0x0F), HIGH);
delay(10);
}
for (int thisPin = 0; thisPin < 17; thisPin++) {
mcpArray[1].pinMode(thisPin, OUTPUT);
mcpArray[1].digitalWrite((thisPin & 0x0F), HIGH);
delay(10);
}
// Simple serial output to indicate the void loop
// is about to start and hold the LEDs HIGH for 5 seconds
Serial.println("Program will start in 5 seconds...");
delay(1000);
Serial.println("4...");
delay(1000);
Serial.println("3...");
delay(1000);
Serial.println("2...");
delay(1000);
Serial.println("1...");
delay(1000);
Serial.println("STARTING Program!!");
}
void loop() {
// while loop to sequence LEDs from 0 to 31 while
// there is hard drive activity present and the
// activity is below 32
while(digitalRead(hddPin)==0 && activity < 32){
// Activate pin 13 (onboard LED) for debugging
digitalWrite(13, HIGH);
// Step activity variable +1 per loop
activity++;
// Activate pins 1 thru 16 of each MCP23017
// sequentially cascading from IC1 to IC2 respectively
mcpArray[activity>>4].digitalWrite((activity & 0x0F), HIGH);
// IF statement to ramp up the speed of the loop
// the closer it gets to being 100%
if(activity > -1 && activity < 12){
delay(30);
}else if(activity > 12 && activity < 26){
delay(15);
} else {
delay(10);
}
// Output to serial for debugging
Serial.println(activity);
}
// while loop to sequence LEDs from 31 to 0 while
// there is hard drive activity present and the
// activity is greater -1
while(digitalRead(hddPin)==1 && activity > -1){
// Deactivate pin 13 (onboard LED) for debugging
digitalWrite(13, LOW);
// Deactivate pins 16 thru 1 of each MCP23017
// sequentially cascading from IC2 to IC1 respectively
mcpArray[activity>>4].digitalWrite((activity & 0x0F), LOW);
// Short delay between each LED turning off
delay(50);
// Step activity variable -1 per loop
activity--;
// Output to serial for debugging
Serial.println(activity);
}
}
I've also attached two photos of the device... yes, its suppose to resemble a tachometer