Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Table of Contents
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
http://www.instructables.com/id/Visual-Computer-Stress-Meter-Arduino/
Author:alecnotalex
I am a human being that enjoys to build things. That's probably all you need to know about me.
This tutorial is interned for Unix users. If I am correct, small tweaking should allow it to work on Windows. Maybe some day I'll re-write it for Windows users.
Image Notes
1. Shows maximum stress.
http://www.instructables.com/id/Visual-Computer-Stress-Meter-Arduino/
Step 1: How it works
You may be wondering how it works at this point, before you get started. All of the real work is done with a perl script.
Image Notes
1. My standard supplies photo.
#!/usr/bin/perl
use Unix::Processors;
use Device::SerialPort;
use Math::Round;
All of these are libraries you need. The first allows you to clock the processor. The next allows you to write to the Serial port, and the last allows you to round numbers.
Now, add:
All of these things initialize the connection with the Arduino. You should change what needs to be changed to make it fit your needs.
This chunk of code clocks the processor and puts it on a scale between 1 and 7. Some things need to be changed, such as your processors minimum clock speed, and
your max divided by the number of leds. For this project, there is 8 leds.
Finally, add:
http://www.instructables.com/id/Visual-Computer-Stress-Meter-Arduino/
This code is in charge of sending it to the Arduino.
Save all that code as clockandsend.pl
Now, this will only clock and send one number. You want to create another script to run this one over, and over again. For example:
#!/usr/bin/perl
while (1)
{
system("/path/clockandsend.pl");
}
As said in the comment, it defines the pins. Now add setup ():
void setup()
{
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
Serial.begin(9600);
}
This just sets the pin-modes, and begins the Serial connection. Remember, the baud rate must be consistent with the perl script.
More code:
These are three variables that are need. Loops is how many times it has looped. Overall is the past ten inputs added together. Avrg is overall / loops.
Add this:
void loop()
{
int input;
if (Serial.available() > 0)
{
input = Serial.read() - '0'; //Takes input
}
if (input != 0) loops++; //makes sure that input is not 0. If it is, it will not be counted
overall += input; //Adds the input to overall
avrg = overall/loops; //Averages it.
if (loops == 10)
{
avrg--; //Decreases avereage by one. Remember in the perl script how we increase it by one?
if (avrg > 0) {digitalWrite(led1, HIGH);}
else {digitalWrite(led1, LOW);}
if (avrg > 1) {digitalWrite(led2, HIGH);}
else {digitalWrite(led2, LOW);}
if (avrg > 2) {digitalWrite(led3, HIGH);}
else {digitalWrite(led3, LOW);}
if (avrg > 3) {digitalWrite(led4, HIGH);}
else {digitalWrite(led4, LOW);}
if (avrg > 4) {digitalWrite(led5, HIGH);}
else {digitalWrite(led5, LOW);}
if (avrg > 5) {digitalWrite(led6, HIGH);}
else {digitalWrite(led6, LOW);}
if (avrg > 6) {digitalWrite(led7, HIGH);}
else {digitalWrite(led7, LOW);}
if (avrg > 7) {digitalWrite(led8, HIGH);}
else {digitalWrite(led8, LOW);} //Make the graph
loops = 0;
overall = 0;
This code simply says "Every ten loops, display the average, and reset everything." The comments should explain it.
Finally, add:
This is included for trouble-shooting purposes. If nothing is lighting up, you can see if it's even trying to light up.
File Downloads
stress.ino (1 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'stress.ino']
Step 5: Set up the Arduino
Obviously, we're going to need to set up the Arduino. The image, created using fritzing, should explain it. The blue things are wires, the red things are leds, and the
resistors are 330 ohm.
http://www.instructables.com/id/Visual-Computer-Stress-Meter-Arduino/
Step 6: Making it all work
Now that you have all these things, you may be wondering how they all come together. Here it is:
Remember, everything must be done in that order. If it's not, it will not work.
Feel free to post any questions you have in the comments, I would love to answer them!
Related Instructables
LoL Shield
Visual Network Wireless Altoids Audio Spectrum
VU Meter by
Threat Level Cycle Computer VU Meter by
dmallen
Indicator by joe How to Graph by Alexdlp How to Send andydoro
by tricky dick Data by Light:
Fiber Optics
[Updated] by
iScience
http://www.instructables.com/id/Visual-Computer-Stress-Meter-Arduino/