Spiel und Theater 4Jhg
Zur Navigation springen
Zur Suche springen
Ultra Long Range Beta Wave Detector
Code
/* CODE for the "Ultra Long Range Beta Wave Detector"
reads value from an analog sensor (0-1023) and maps this to the analog output range (0-255)
to control a vibration motor. at random intervals the sensor values control the speed of the
motor or there is a pause and nothing happens.
*/
#define minPauseTime 30000
#define maxPauseTime 300000
#define minActiveTime 10000
#define maxActiveTime 60000
#define inputPin A0
#define outputPin 5
long inputValue;
long mappedValue;
long active_random_interval = 0;
long pause_random_interval = 0;
bool activate = false;
long double timeStamp = 0; //for keeping track of active time
void setup() {
// initialize the serial communication:
Serial.begin(9600);
pinMode(inputPin, INPUT);
pinMode(outputPin, OUTPUT);
active_random_interval = random(minActiveTime, maxActiveTime);
}
void loop() {
if (activate == false) {
timeStamp = millis();
activate = true;
active_random_interval = random(minActiveTime, maxActiveTime);
Serial.println(active_random_interval);
}
if (millis() > (timeStamp + active_random_interval)) {
analogWrite(outputPin, 0);
pause_random_interval = random(minPauseTime, maxPauseTime);
Serial.println(pause_random_interval);
delay(pause_random_interval);
activate = false;
}
if (activate == true) {
// send the value of analog input 0:
inputValue = analogRead(inputPin);
Serial.print(inputValue);
Serial.print("\t");
mappedValue = map(inputValue, 0, 1023, 120, 255);
Serial.print(mappedValue);
Serial.println();
analogWrite(outputPin, mappedValue);
delay(20); // wait a bit for the analog-to-digital converter to stabilize
}
}