Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: cook.cpp
- Revision:
- 0:ae5d19a716e1
diff -r 000000000000 -r ae5d19a716e1 cook.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cook.cpp Wed Mar 05 05:17:45 2014 +0000
@@ -0,0 +1,237 @@
+/* cook.cpp */
+
+#include "global.h"
+
+/**
+ * Parameters
+ */
+int aori_times = 13;
+
+double hand_interval=0.5, egg_gasya_times=6, rice_gasya_times=12;
+int highest=0, lowest=-750, middle=-450; //rotary encoder
+
+double servetime = 9.0;
+
+/**
+ * Functions
+ */
+void AORI() {
+
+ int top, count=0;
+ if (MS_A.read()) {
+ top=ON;
+ } else {
+ top=OFF;
+ }
+
+ setspeed(duty_A, _A_);
+ while(count<aori_times) {
+ if(MS_A.read()!=top) {
+ if(top==OFF) {
+ top=ON;
+ count++;
+ }
+ else {
+ top=OFF;
+ }
+ }
+ wait(0.05);
+ }
+ setspeed(dutyr_A, _A_);
+ while(MS_A.read()) {
+ wait(0.05);
+ }
+ setspeed(STOP, _A_);
+}
+
+void updown(int trg) {
+
+ if(hight.getPulses()<trg) {
+ setspeed(dutyu_U, _U_);
+ if(trg==highest) {
+
+ while(MS_U.read()==1 && hight.getPulses()<trg) {
+ wait(0.05);
+ }
+ setspeed(STOP, _U_);
+
+ }
+ else{
+ while(hight.getPulses()<trg) {
+ wait(0.05);
+ }
+ setspeed(STOP, _U_);
+ }
+ }
+
+ else if(hight.getPulses()>trg) {
+ setspeed(dutyd_U, _U_);
+
+ if(trg==highest) {
+
+ while(MS_U.read()==1 && hight.getPulses()>trg) {
+ wait(0.05);
+ }
+ setspeed(STOP, _U_);
+
+ }
+ else{
+ while(hight.getPulses()>trg) {
+ wait(0.05);
+ }
+ setspeed(STOP, _U_);
+ }
+ }
+}
+
+void gasya ( short n ) {
+ for( short i=0; i<n; i++ ) {
+ UFO = CLOSE;
+ wait(hand_interval);
+ UFO = OPEN;
+ wait(hand_interval);
+ }
+}
+
+void egg_hand_rot(int n) {
+
+ UFO = CLOSE;
+ updown(lowest);
+ wait(0.5);
+ gasya(n);
+ wait(0.5);
+ UFO = CLOSE;
+ wait(0.3);
+ updown(highest);
+ //UFO = CLOSE;
+}
+
+void rice_hand_rot(int n) {
+
+ for (short i=0; i<n; i++) {
+ UFO = CLOSE;
+ updown(lowest);
+ wait(0.3);
+ gasya(rice_gasya_times);
+ UFO = CLOSE;
+ wait(0.3);
+ updown(middle);
+ wait(0.3);
+ UFO = OPEN;
+ wait(1);
+ UFO = CLOSE;
+ }
+ updown(highest);
+}
+
+void merry() {
+ //int count;
+ setspeed(duty_M, _M_);
+ wait(1);
+ while(MS_M.read()) {
+ wait(0.1);
+ }
+ setspeed(STOP, _M_);
+}
+
+void serve() {
+ setspeed(duty_S, _S_);
+ wait(servetime);
+ setspeed(STOP, _S_);
+ wait(4.0);
+ setspeed(dutyr_S, _S_);
+ while(MS_S.read()) {
+ wait(0.05);
+ }
+ setspeed(STOP, _S_);
+}
+
+void cook() {
+ pc.attach(cook_stop, Serial::RxIrq);
+ double gg=0.7;
+ wait(1.0);
+
+ //merry rice
+ if(STOP_STATUS) {
+ pc.printf( "merry egg \r\n" );
+ merry();
+ wait(gg);
+ }
+
+ //hand rice
+ if(STOP_STATUS) {
+ pc.printf( "hand \r\n" );
+ egg_hand_rot(egg_gasya_times-2);
+ wait(gg);
+ }
+
+ //merry egg
+ if(STOP_STATUS) {
+ pc.printf( "merry rice \r\n" );
+ merry();
+ wait(gg);
+ }
+
+ //hand egg
+ if(STOP_STATUS) {
+ pc.printf( "hand \r\n" );
+ egg_hand_rot(egg_gasya_times*2);
+ //rice_hand_rot(2);
+ wait(gg);
+ }
+
+ //merry, hand 3
+ if(STOP_STATUS) {
+ pc.printf( "merry 3 \r\n" );
+ merry();
+ wait(gg);
+ pc.printf( "hand \r\n" );
+ egg_hand_rot(egg_gasya_times);
+ //rice_hand_rot(1);
+ wait(gg);
+ }
+
+ //merry, hand 4
+ if(STOP_STATUS) {
+ pc.printf( "merry 4 \r\n" );
+ merry();
+ wait(gg);
+ pc.printf( "hand \r\n" );
+ egg_hand_rot(egg_gasya_times);
+ //rice_hand_rot(2);
+ wait(gg);
+ }
+
+ //AORI
+ if(STOP_STATUS) {
+ pc.printf( "aori \r\n" );
+ RISE1 = UP;
+ wait(3.0);
+ AORI();
+ wait(1);
+ RISE1 = DOWN;
+ wait(2);
+ wait(gg);
+ }
+
+ // serve
+ if(STOP_STATUS) {
+ pc.printf( "serve \r\n" );
+ serve();
+ wait(3.0);
+ }
+
+ //end processing
+ if(STOP_STATUS) {
+ pc.printf( "finish!! \r\n" );
+ }
+ else if(!STOP_STATUS) {
+ pc.printf( "stop \r\n" );
+ STOP_STATUS = true;
+ }
+
+ wait(0.2);
+ pc.putc('f'); //bgm stop
+ wait(0.2);
+ __disable_irq(); //stop interrupt
+}