Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Divya Inaganti
- * final project- Divya's Divine Fan Device
- */
- const int controlPin1 = 2; // connected to pin 7 on the H-bridge
- const int controlPin2 = 3; // connected to pin 2 on the H-bridge
- const int enablePin = 9; // connected to pin 1 on the H-bridge
- // create some variables to hold values from your inputs
- int motorEnabled = 0; // current state of the On/Off switch
- int motorDirection = 0; // current state of the direction switch
- int motorSpeed = 255; // speed of the motor
- int timeVal;
- int soundsensorPin = A0;
- int soundsensorValue= 0;
- const int LEDred= 6;
- const int LEDblue= 4;
- const int LEDwhite= 5;
- void setup() {
- pinMode(LEDred, OUTPUT);
- pinMode(LEDblue, OUTPUT);
- pinMode(LEDwhite, OUTPUT);
- pinMode(controlPin1, OUTPUT);
- pinMode(controlPin2, OUTPUT);
- pinMode(enablePin, OUTPUT);
- Serial.begin(9600);
- // pull the enable pin LOW to start
- digitalWrite(enablePin, LOW);
- }
- void loop()
- {
- soundsensorValue = analogRead(soundsensorPin);
- if(soundsensorValue > 110)
- {
- Serial.println(soundsensorValue, DEC);
- delay(250);
- digitalWrite(LEDred, HIGH);
- digitalWrite(LEDblue, HIGH);
- digitalWrite(LEDwhite, HIGH);
- clapcounting();
- }
- if (motorDirection == 1) {
- digitalWrite(controlPin1, HIGH);
- digitalWrite(controlPin2, LOW);
- } else {
- digitalWrite(controlPin1, LOW);
- digitalWrite(controlPin2, HIGH);
- }
- // if the motor is supposed to be on
- if (motorEnabled == 1) {
- // PWM the enable pin to vary the speed
- analogWrite(enablePin, motorSpeed);
- } else { // if the motor is not supposed to be on
- //turn the motor off
- analogWrite(enablePin, 0);
- }
- }
- void clapcounting()
- {
- int claps = 1;
- timeVal = millis();
- while(millis()- timeVal < 3000)
- {
- soundsensorValue = analogRead(soundsensorPin);
- if(soundsensorValue > 110)
- {
- claps++;
- Serial.println(soundsensorValue, DEC);
- delay(250);
- }
- }
- if (claps== 1)
- {
- motorEnabled= !motorEnabled;
- }
- else if (claps== 2)
- {
- if (motorSpeed== 255)
- {
- motorSpeed= 120;
- }
- else if (motorSpeed== 120)
- {
- motorSpeed= 255;
- }
- else if (claps== 2)
- {
- motorDirection= ! motorDirection;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement