
pet feeder code (not final; still need to add in timer code).
Dependencies: mbed C12832 Servo
Revision 1:240702e500bd, committed 2018-11-20
- Comitter:
- wlewinger
- Date:
- Tue Nov 20 20:23:10 2018 +0000
- Parent:
- 0:cfa7fee348c5
- Commit message:
- Bill updates 2018-11-20
Changed in this revision
--- a/FSR.lib Tue Nov 20 12:29:44 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://os.mbed.com/users/cshao06/code/FSR/#d9520bf7eb9e
--- a/Servo.lib Tue Nov 20 12:29:44 2018 +0000 +++ b/Servo.lib Tue Nov 20 20:23:10 2018 +0000 @@ -1,1 +1,1 @@ -http://os.mbed.com/users/simon/code/Servo/#36b69a7ced07 +http://developer.mbed.org/users/matsu/code/Servo/#80a784fc179c
--- a/main.cpp Tue Nov 20 12:29:44 2018 +0000 +++ b/main.cpp Tue Nov 20 20:23:10 2018 +0000 @@ -16,32 +16,40 @@ #include "Servo.h" #include "C12832.h" #include "IR_Dist.h" -#include "FSR.h" +//#include "FSR.h" DigitalIn centre(p14); //joystick centre DigitalIn down(p12); //joystick down DigitalIn up(p15); //joystick up -Servo motor(p21); //servo motor +Servo myservo(p21); //servo motor C12832 lcd(p5, p7, p6, p8, p11); //lcd screen AnalogIn fsr(p17); //force sensitive resistor AnalogIn distance(p18); //ir sensor -myservo.calibrate(0.0005,45); //calibrating servo speed and starting position +int hours = 0; +int minutes = 0; + + +//myservo.calibrate(0.0005,45); //calibrating servo speed and starting position /** code for servo motor to run */ -void servo() +void servo(float fsraverage) { - if (fsraverage = 0) ( //will only run if the fsr reading is below a certain value - myservo = 0; //position of the servo is initially at its starting poitn + if (fsraverage == 0) { //will only run if the fsr reading is below a certain value + myservo.write(0.0); //position of the servo is initially at its starting poitn wait(1); //waits 1 second - myservo = 1; //moves the servo 90 degrees + myservo.write(1.0); //moves the servo 90 degrees wait(1); //waits another second + myservo.write(0.0); //position of the servo is initially at its starting poitn + wait(1); //waits 1 second } } - int main() -{ + + +int main() { + float iraverage; //averages ir sensor input float fsraverage; //averages fsr input while(1) { @@ -66,35 +74,34 @@ /** condition at which the system will not work */ - if (fsr = 1) { - myservo = 0; + if (fsr == 1) { + myservo.write(0.0); } /** portion size settings */ - if ( - if (centre) { //if centre joystick is pressed +// if ( + if (centre.read()) { //if centre joystick is pressed lcd.printf("1"); //will print a '1' on the lcd screen - set = 1; //sets the value of set to 1 - } + set = 1; //sets the value of set to 1 + } - if (down) { //if the down joystick is pressed - lcd.print("2"); //prints '2' on the lcd screen - set = 2; //sets the value of set to 2 + if (down.read()) { //if the down joystick is pressed + lcd.printf("2"); //prints '2' on the lcd screen + set = 2; //sets the value of set to 2 } - if (up) ( //if the up joystick is pressed - lcd.print("3") //prints '3' on the lcd screen - set = 3; //sets the value of set to 3 - } + if (up.read()) { //if the up joystick is pressed + lcd.printf("3"); //prints '3' on the lcd screen + set = 3; //sets the value of set to 3 + } /** automatically dispensing food at certain times of day */ -if (hours = 6 || hours = 12 || hours = 18) { //if the hours is equal to either 6, 12 or 18 - int i - for (i = set; i = i + 1) { //will executed the code a number of times, dependent on what the value of set is - servo(); //executes servo code + if (hours == 6 || hours == 12 || hours == 18) { //if the hours is equal to either 6, 12 or 18 + for (int i = 0; i < set; i++) //will executed the code a number of times, dependent on what the value of set is + servo(fsraverage); //executes servo code } } }