Tone_LED_Random
Auf dieser Unterseite stelle ich den Aufbau und das Programm für z. B. eine "Tamagothi-Nachahme".
Man braucht:
- einen Arduino Uno (Mega funktioniert natürlich auch!)
- 2 LED´s
- 1 Passiv Lautsprecher
Sktech:
#include "Tone_Random.h"
int LED1=10;
int LED2=9;
int Tone=8;
void setup() {
pinMode (LED1, OUTPUT);
pinMode (LED2, OUTPUT);
}
void loop() {
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
if (random(500)==1)
{ digitalWrite (LED1, LOW);
digitalWrite (LED2, LOW);
delay(50);
}
delay(10);
}
---------------------------------------------
int sensor=A1;
int sensorSchwelle=20;
int lichtNormal;
//int speakerPin=7;
const int buzzer = 7; //buzzer to arduino pin 7
void Tone_Random() {
pinMode(buzzer, OUTPUT); // Set buzzer - pin 7 as an output
lichtNormal = analogRead(sensor);
if (analogRead(sensor)>lichtNormal+sensorSchwelle){
tone(buzzer, 20); // Send sound signal...
delay(1000); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(1000); // ...for 1sec}
}
else{
noTone(buzzer);
}
delay(10);
}