Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <AFMotor.h>
- #include <Servo.h>
- #include <OneWire.h>
- #include <DallasTemperature.h>
- AF_DCMotor motor1(1);
- //AF_DCMotor motor(1, MOTOR12_64KHZ);
- Servo servo1;
- const int buzzerPin = 9; //servo2
- #define ONE_WIRE_BUS 10 //servo1
- const int currentPin = A0; //ACS712
- // Setup a oneWire instance to communicate with any OneWire devices
- OneWire oneWire(ONE_WIRE_BUS);
- // Pass our oneWire reference to Dallas Temperature sensor
- DallasTemperature sensors(&oneWire);
- // Adafruit Motor Board https://cdn-learn.adafruit.com/downloads/pdf/adafruit-motor-shield.pdf
- // China Clone: http://makeitanywhere.org/nyc/index.php?option=com_content&view=article&id=6&Itemid=132#!DK_Motorshield_V1_Top_B
- bool stopped = false;
- float threshold = 300;
- void setup()
- {
- Serial.begin(9600);
- pinMode(buzzerPin, OUTPUT);
- pinMode(ONE_WIRE_BUS, INPUT);
- Serial.println("Loading temperature");
- sensors.begin();
- }
- void loop()
- {
- sensors.requestTemperatures();
- float mytemp = sensors.getTempCByIndex(0);
- Serial.println(mytemp);
- int myspeed = 200;
- long myduration = 1000;
- long mywait = 0;
- if (mytemp > 10) { //mescolamento continuo lento
- myspeed = 100;
- myduration = 30000;
- mywait = 1000;
- }
- if (mytemp < 10 && mytemp > 5 ) { //velocizziamo la perdita di calore
- myspeed = 230;
- myduration = 10000;
- mywait = 10000;
- }
- if (mytemp < 5 && mytemp > 3 ) { //mantecatura
- myspeed = 170;
- myduration = 20000;
- mywait = 5000;
- }
- if (mytemp < 3) { //congelamento
- myspeed = 200;
- myduration = 10000;
- mywait = 30000;
- }
- motor1.run(RELEASE);
- motor1.setSpeed(myspeed);
- if (stopped == false){
- motor1.run(FORWARD);
- stopped = delayMotor(myduration);
- } else {
- innoallagioia();
- }
- motor1.run(RELEASE);
- delay(mywait);
- }
- bool delayMotor(long duration)
- {
- int window = 100;
- for(int n = 0; n < duration; n=n+window) {
- float average = 0;
- for(int i = 0; i < window; i++) {
- average = average + (0.0264 * analogRead(currentPin) -13.51);
- delay(1);
- }
- average = (average/window)*1000; //milliampere
- Serial.println(average);
- if (average > threshold) return true;
- }
- return false;
- }
- void innoallagioia()
- {
- // create variables for notes
- int c6 = 1047;
- int d6 = 1157;
- int e6 = 1319;
- int f6 = 1397;
- int g6 = 1568;
- int a6 = 1760;
- int b6 = 1976;
- int c7 = 2093;
- // create variables for note durations
- int whole = 2000; //whole note
- int half = whole/2; //half note
- int quarter = whole/4; //quarter note
- int eighth = whole/8; //eighth
- int sixteenth = whole/16; //sixteenth
- // create a variable for a gap between notes
- int gap = 20;
- tone(buzzerPin, e6, quarter);
- delay(quarter+gap);
- tone(buzzerPin, e6, quarter);
- delay(quarter+gap);
- tone(buzzerPin, f6, quarter);
- delay(quarter+gap);
- tone(buzzerPin, g6, quarter);
- delay(quarter+gap);
- tone(buzzerPin, g6, quarter);
- delay(quarter+gap);
- tone(buzzerPin, f6, quarter);
- delay(quarter+gap);
- tone(buzzerPin, e6, quarter);
- delay(quarter+gap);
- tone(buzzerPin, d6, quarter);
- delay(quarter+gap);
- tone(buzzerPin, c6, quarter);
- delay(quarter+gap);
- tone(buzzerPin, c6, quarter);
- delay(quarter+gap);
- tone(buzzerPin, d6, quarter);
- delay(quarter+gap);
- tone(buzzerPin, e6, quarter);
- delay(quarter+gap);
- tone(buzzerPin, e6, quarter);
- delay(quarter+gap);
- tone(buzzerPin, d6, quarter);
- delay(quarter+gap);
- tone(buzzerPin, d6, half);
- delay(half+gap);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement