@@ -57,42 +57,56 @@ void setup()
5757 myservo.write (60 );
5858}
5959
60- uint32_t last_valid_timestamp = 0 ;
6160
6261void loop ()
6362{
64- if ((millis () - last_valid_timestamp) > 200 ) {
65- pixels.fill (0 );
66- pixels.show ();
67- }
68-
6963 if ( usb_web.available ()) {
70- char val;
7164 digitalWrite (LED_BUILTIN, HIGH);
7265 Serial.print (" -> " );
73- val = usb_web.read ();
66+ char val = usb_web.read ();
7467 digitalWrite (LED_BUILTIN, LOW);
7568 Serial.print (" Read value: " ); Serial.println (val, DEC);
7669
7770 if (val == 1 ) { // Target bin #1
7871 pixels.fill (0xFFFF00 );
7972 pixels.show ();
80- last_valid_timestamp = millis ();
73+ Serial.println (" CEREAL!" );
74+
75+ myservo.write (0 ); // push cereal to one side
76+ delay (2000 ); // wait
77+ for (int pos = 0 ; pos <= 75 ; pos++) { // return servo
78+ myservo.write (pos);
79+ delay (5 );
80+ }
81+ delay (1000 ); // another wait before we continue
82+
8183 } else if (val == 2 ) { // Target bin #2
8284 pixels.fill (0xFF000FF );
8385 pixels.show ();
84- last_valid_timestamp = millis ();
85- } else {
86- pixels.fill (0 );
87- pixels.show ();
86+ Serial.println (" MALLOW!" );
87+
88+ myservo.write (180 ); // push mallows to other side
89+ delay (2000 ); // wait
90+ for (int pos = 180 ; pos >= 75 ; pos--) { // return servo
91+ myservo.write (pos);
92+ delay (5 );
93+ }
94+ delay (1000 ); // another wait before we continue
95+ }
96+ pixels.fill (0 );
97+ pixels.show ();
98+
99+ while (usb_web.available ()) {
100+ usb_web.read ();
101+ delay (10 );
88102 }
89103 } else {
90- // no webserial data
91- for (int pos = 60 ; pos <= 90 ; pos += 1 ) { // slowly goes from 60 degrees to 90 degrees
104+ // no webserial data, tick tock the servo
105+ for (int pos = 60 ; pos <= 90 ; pos++ ) { // slowly goes from 60 degrees to 90 degrees
92106 myservo.write (pos);
93107 delay (3 );
94108 }
95- for (int pos = 90 ; pos >= 60 ; pos -= 1 ) { // goes back to 60
109+ for (int pos = 90 ; pos >= 60 ; pos-- ) { // goes back to 60
96110 myservo.write (pos);
97111 delay (3 );
98112 }
0 commit comments