Hi all,
I am new to programming the arduino code, but have managed to get what I wanted to do working on an Uno..yay for me!..
But sadly I am unable to get it to work on a digispark attiny 16hz 5v board..
The program should detect EMF or any electricity around an antenna and sound an alarm,it works on uno but I get nothing from the Attiny, ..here is the code..
#define sample 300 //this is how many samples the device takes per reading
//more information for #define http://arduino.cc/en/Reference/Define
int inPin = A3; //analog 5
float val; //where to store info from analog 5
int pin12 = 1; //output of red led
int pin5 = 5;
int array1[sample]; //creates an array with number of elements equal to "sample"
//more information about arrays http://arduino.cc/en/Reference/Array
unsigned long averaging; //the program uses this variable to store the sum of each array it makes
void setup() {
Serial.begin(9600);
pinMode (5,OUTPUT);
}
void loop() {
for(int i = 0; i < sample; i++){ //this code tells the program to fill each element in the array we made with
array1[i] = analogRead(inPin); //information from the antenna wire coming out of the Arduino
averaging += array1[i]; //more information about for loops http://arduino.cc/en/Reference/For
} //the averaging line is simply saying: add averaging to whatever is in array position i
//averaging += array[i] is the same as averaging = averaging + array[i]
//for more information about += http://arduino.cc/en/Reference/IncrementCompound
Serial.println(val);
val = averaging / sample; //here the program takes the sum of all numbers in array1, and divides by the number of elements "sample"
val = constrain(val, 0, 100); //this constrains the variable value to between two numbers 0 and 100
val = map(val, 0, 100, 0, 255); //for more information about constrain http://arduino.cc/en/Reference/Constrain
analogWrite( pin12, val);
analogWrite( pin5, val);//the map statement tells the program to map out 0-100 to 0-255, 255 is
//the threashold of analogWrite for more information about map http://arduino.cc/en/Reference/Map
averaging = 0; //this line of code sets averaging back to zero so it can be used again
}
Hope someone can help me?, sorry if this is in the wrong place on the Forum .