//------------------------------------------------------------------------------ // CoinCountA.c Written by Andreas Dreier (alias ®³) for CC8 //------------------------------------------------------------------------------ // This bot will count, detect and calculate a lot of coins. It detect all eight // different coins of the European currency: EURO-Coins // // 1 ct = 0.01 € Coins of the following countries are supported: // 2 ct = 0.02 € - Austria - Italy // 5 ct = 0.05 € - Belgium - Luxembourg // 10 ct = 0.10 € - Finland - Netherlands // 20 ct = 0.20 € - France - Portugal // 50 ct = 0.50 € - Germany - Spain // 1 € = 1.00 € - Greece // 2 € = 2.00 € - Ireland >>>>> 96 different coins :-) // //------------------------------------------------------------------------------ // How does it works? // // The process will seperated into 3 tasks: // // 1. Isolate the coins --> Isolation unit // 2. Sort the coins --> Sorting unit // 3. Count the coins --> Detecting unit // // +--------------------------+ // | Isolation | // | Coins unit | // | | | // | \ V / | // | \ / | // | \ OOOOOO/ | // | \ OOOO/ | +--------------------------------------+ // | O O O O S2L | | Sorting unit | // | MB----------------------------| | // | conveyor belt | |1ct 2ct 10ct 5ct 20ct 1€ 50ct 2€ | // +--------------------------+ +--------------------------------------+ // | | | | | | | | | | | | | | | | // | | | | |O| |O| | | | | | | |O| // |O| | | |O| |O| | | |O| | | |O| // |O| |O| |O| |O| |O| |O| |O| |O| // +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ // // +--|--+ // +---| S2T |-----------------------------+ // | |S1 S3| Detecting unit | // +---|MA MC|-----------------------------+ // +-----+ //------------------------------------------------------------------------------ // I have build a little machine, which realize this. The heart of this bot is // the LEGO Mindstorms RCX. The machine consists of 3 motors, 2 rotation // sensors, 1 light sensor and 1 touch sensor. This devices are connected on the // following scheme: // // +-----------------------+ Sensors: // | +---+ +---+ +---+ | // | |Rot| |Lgt| |Rot| | S1 : Rotation sensor for left/right // | |L/R| |Tou| |U/D| | // | +---+ +---+ +---+ | S2L : Light sensor for coin detection // | 1 2 3 | // | View Prgm | S2T : Touch sensor for slot height detection // | +-----------+ | // | | -8888 X 8 | | S3 : Rotation sensor for up/down // | +-----------+ | // | On-Off Run | Motors: // | A B C | // | +---+ +---+ +---+ | MA : Motor for slot height detection unit // | |Mot| |Mot| |Mot| | // | |sen| |con| |L/R| | MB : Motor for conveyor belt // | +---+ +---+ +---+ | // +-----------------------+ MC : Motor for movement the detection unit // //------------------------------------------------------------------------------ // On which way will the bot count the coins? // // The bot doesn't "count" the coins - it will detect the height of the coins // at the slot. On this way it can recognize all coins of a coin sort with one // detection step! If it knows the height of the coin stack, it can calculate // how much coins are in it :-) // // To reach this, the height of the stack must be realized with a very big // exactness. This will be reached by direct combination of motor (MA) and // rotation sensor (S3). After this a gear box with a worm will reduce the speed // and maximize the resolution of stack detection. On this way, there are 8 // ticks (half rotation of Motor) to recognize the height of the smallest coin. // // The touch sensor (S2T) is installed on the top of the detecting unit which is // direct mounted with the sensing device. It respond at the least contact of // the sensing device. // // The second rotation sensor (S1) detects the relative position from the left // end of the detection unit. A motor (MC) at the base of the detection unit // moved the whole unit with the RCX. // // The last sensor (S2L) is implemented between the isolation unit and the sor- // ting unit. It detects every coin, which is released by the conveyor belt and // spinning down into the sorting unit. The conveyor belt will driven by the // third motor (MB). //------------------------------------------------------------------------------ // Main steps of program: // // 1. Preparing RCX // 1.1. Defining the sensors // 1.2. Defining the background tasks // 1.3. Move to initialisation position // 1.4. Check the ground value // 2. Sorting the coins // 2.1. Start conveyor belt and wait for first coin // 2.2. Wait until last coin was detected 5 seconds ago // 3. Checking the stacks // 3.1. Move to every slot and check the stack height // 3.2. Display the result of the current slot // 4. Show Result // 4.1. Show for every slot: Coin-Type, Count of coins, amount of coins // 4.2. Total sum of coins // 4.3. Duration of detecting process // 4.4. Repeat 4.1 - 4.4 until button RUN will pressed. // 5. Reset the RCX // 5.1. Stop all background processes // 5.2. Reset the sensors //------------------------------------------------------------------------------ // Additional functions: // // By pressing the button VIEW you can show the sensor values: // 0 - no periodically update of display (normal function) // 1 - show value of rotation sensor S1 (vertical position of sensor) // 2 - show the raw value of sensor S2T and S2L // 3 - show value of rotation sensor S3 (relative position to legt end) //------------------------------------------------------------------------------ // Display update for a normal process: // // <<----- start of scan-process // // Init << Initialize the bot // // StArt << Start of process // COIn? << Wait for first coin // // LASt? << Wait for last coin // LAST1 .. LAST5 << Time after last coin // // StOP << Stop sorting process // // Scan << Start scanning process // SLot1 1 ct 0051_ 8n 0.08S << // SLot2 2 ct 009F_ 16n 0.32S << For every slot display: // SLot3 10 ct 0072_ 10n 2.00S << - slot number // SLot4 5 ct 008A_ 14n 0.70S << - coin type // SLot5 20 ct 00AE_ 14n 2.80S << - value of ground sensor // SLot6 1 EUR 0109_ 19n 19.00S << - number of coins // SLot7 50 ct 0062_ 7n 3.50S << - amount of coins at slot // SLot8 2 EUR 0035_ 4n 8.00S << // // <<----- end of scan-process // // 1 ct 8n 0.05S << Display until RUN pressed: // 2 ct 16n 0.20S << // 10 ct 10n 0.70S << For every coin type: // 5 ct 14n 0.40S << - coin type // 20 ct 14n 2.00S << - number of coins // 1 EUR 19n 6.00S << - amount of coins // 50 ct 7n 3.00S << // 2 EUR 4n 6.00S << // 91n << Total number of coins // 35.38T << Total amount of all coins // 4.10t << Duration for scan process // //------------------------------------------------------------------------------ // Known problems and limitations: // // - The bot can only count estimate 32 - 36 coins of every kind // Maximum number of coins are near 256 - 288. But I didn't test it, because // I doesn't have so a great number of coins at home :-( // // - Unload of sorted coins is difficulty - I have to remove the slot unit and // remove the coin stacks by hand :-( // // - If I had have 8 additional light sensors for every slot, the additional // time for counting coins would be zero ... perhaps next time ;-) // //------------------------------------------------------------------------------ // Electrical parts: 1 RCX // 2 Rotation sensor // 1 Light sensor // 1 Touch sensor // 2 9V Power motor 71427c01 // 1 9V Power motor 47154c01 //------------------------------------------------------------------------------ // Programming: brickOS 0.2.6 // // Why? Because brickOS is the best programming language // For the RCX! // // Many thanks to Marcus L. Noga and all the people who // developed brickOS! //------------------------------------------------------------------------------ //Pictures of the TypeWriter: // // Album: // http://festum.de/1000steine/myimages/CC8A // // Video: // http://festum.de/1000steine/album/CC8A/Init_Bot_001.mov 6244 KB // http://festum.de/1000steine/album/CC8A/IsolationUnit.MOV 4405 KB // http://festum.de/1000steine/album/CC8A/Sorting_backstage.MOV 4306 KB // http://festum.de/1000steine/album/CC8A/Sorting_Front.MOV 3649 KB // // Photo: // http://festum.de/1000steine/myimages/CC8A/Complete_CoinSorter_front // http://festum.de/1000steine/myimages/CC8A/Complete_CoinSorter_backstage_001 // http://festum.de/1000steine/myimages/CC8A/Detection_unit // http://festum.de/1000steine/myimages/CC8A/Sorting_unit // http://festum.de/1000steine/myimages/CC8A/Slot_unit // http://festum.de/1000steine/myimages/CC8A/Bot_at_init_position // http://festum.de/1000steine/myimages/CC8A/Coins_at_start_position_input // http://festum.de/1000steine/myimages/CC8A/Coins_at_start_position_output // http://festum.de/1000steine/myimages/CC8A/Conveyor_belt_init_position_001 // http://festum.de/1000steine/myimages/CC8A/Coins_at_slot // http://festum.de/1000steine/myimages/CC8A/Detection_unit_detail // http://festum.de/1000steine/myimages/CC8A/Output_RCX // http://festum.de/1000steine/myimages/CC8A/Slot_sensor_detail // http://festum.de/1000steine/myimages/CC8A/Sorting_unit_detail // http://festum.de/1000steine/myimages/CC8A/Sorting_unit_mask // //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // Including of brickOS routines //------------------------------------------------------------------------------ #include #include #include #include #include #include #include //------------------------------------------------------------------------------ // Defining of constants //------------------------------------------------------------------------------ #define DEBUG 0 // 0=No debug mode / 1=debug mode #define SENSOR_LR ROTATION_1 // Alias for sensor 1 (S1) #define SENSOR_GROUND SENSOR_2 // Alias for sensor 2 (S2T and S2L) #define SENSOR_UD ROTATION_3 // Alias for sensor 3 #define POS_UPPER 0x01D0 // Stop at upper Position from ground #define POS_1_CENT 0x0006 // Position of slot for coin type 1 Cent #define POS_2_CENT 0x0012 // Position of slot for coin type 2 Cent #define POS_10_CENT 0x001E // Position of slot for coin type 10 Cent #define POS_5_CENT 0x002A // Position of slot for coin type 5 Cent #define POS_20_CENT 0x0036 // Position of slot for coin type 20 Cent #define POS_1_EURO 0x0041 // Position of slot for coin type 1 Euro #define POS_50_CENT 0x004E // Position of slot for coin type 50 Cent #define POS_2_EURO 0x0059 // Position of slot for coin type 2 Euro #define NUMBER_OF_COINS 8 // 1, 2, 5, 10, 20 and 50 Cent + 1, 2 Euro #define MAX_WAIT_COIN 5000 // Wait 5 seconds after last coin #define SENS2_MARK1 0x2000 // First critical value of sensor 2 #define SENS2_MARK2 0xC000 // Second critical value of sensor 2 //------------------------------------------------------------------------------ // Defining of complex structure //------------------------------------------------------------------------------ typedef struct { int value; // account of 1 coin int count; // number of coins at slot int coin_height; // height of 1 coin int position; // position relative to left end of ramp int cordelta; // correction of base of slot int sum; // = count * value char name[6]; // name of the coin } CoinRef; //------------------------------------------------------------------------------ // Defining of complex structure values //------------------------------------------------------------------------------ static const note_t Sound0[] // Melody to played on every detected = { { PITCH_C4, 4 }, // coin { PITCH_END, 0 } }; // static const CoinRef coinref[ NUMBER_OF_COINS ] = { // value coin_height cordelta name // count position sum { 1, 0, 0x000A, POS_1_CENT, 2, 0, "1 ct " }, //--- 1 cent coin { 2, 0, 0x000A, POS_2_CENT, 2, 0, "2 ct " }, //--- 2 cent coin { 10, 0, 0x000B, POS_10_CENT, 2, 0, "10 ct" }, //--- 10 cent coin { 5, 0, 0x000A, POS_5_CENT, 3, 0, "5 ct " }, //--- 5 cent coin { 20, 0, 0x000C, POS_20_CENT, 5, 0, "20 ct" }, //--- 20 cent coin { 100, 0, 0x000E, POS_1_EURO, 5, 0, "1 EUR" }, //--- 1 euro coin { 50, 0, 0x000D, POS_50_CENT, 5, 0, "50 ct" }, //--- 50 cent coin { 200, 0, 0x000C, POS_2_EURO, 5, 0, "2 EUR" } //--- 2 euro coin }; //------------------------------------------------------------------------------ // Global program values //------------------------------------------------------------------------------ time_t last_coin; // Timestamp (ms) of last detectec coin time_t start_time; // Timestamp of program start int total_sum; // Total sum of all coins int total_num; // Total number of all coins //------------------------------------------------------------------------------ // This function displayed a given value with the format "#0.00". //------------------------------------------------------------------------------ void ShowValue( int value ) { int rest; // Variable for displaying digit int pos; // Variable of rest of value pos=0; // Position for refreshing next digit cputs( " 000 " ); // Inital display _0.00_ while( value > 0 ) // While value is greater than zero { // rest = value % 10; // Compute the rest for next iteration value = value / 10; // Compute the digit for displaying pos++; // Increment position for display digit cputc( '0'+rest, pos); // Update the display at actual position } // dlcd_show( LCD_3_DOT ); // Show decimal point between pos 3 and 2 } //------------------------------------------------------------------------------ // This function displayed a given value with the format "###0". //------------------------------------------------------------------------------ void cputw_decimal( int value ) { int rest; // Variable for displaying digit int pos; // Varialbe of rest of value pos=0; // Position for refreshing next digit cputs( " 0 " ); // Initial display ___0_ while( value > 0 ) // While value is greater than zero { // rest = value % 10; // Compute the rest for next iteration value = value / 10; // Compute the digit for displaying pos++; // Increment position for display digit cputc( '0'+rest, pos); // Update the display at actual position } } //------------------------------------------------------------------------------ // This function displayed the given time (ms) with the format "_0.00_" // The given time will redimension from ms to s and recalculated from seconds to // a decimal format for output: // // value = 100 * ( ( t/1000 ) / 60 ) + ( ( t / 1000 ) % 60 ) // //------------------------------------------------------------------------------ void ShowTime( time_t t ) { int secs; // Converted value from ms to s int min; // Minute part of converted value int sec; // Seconds part of converted value int value; // Converted decemal value for displaying secs = t / TICKS_PER_SEC; // Convert ms to s min = secs / 60; // Calculate the minutes for display sec = secs % 60; // Calculate the seconds for display value = min * 100 + sec; // Calculate the displaying value ShowValue( value ); // Show the displaying value } //------------------------------------------------------------------------------ // This procedure will move the slot sensor down until it will have contact with // ground of coin slot. After it, it resets the rotation sensor of coin detector // and moved back this sensor to the upper position (relative to the new botton // position) //------------------------------------------------------------------------------ void ResetGround() { motor_a_dir( fwd ); // Move slot sensor down ... motor_a_speed( MAX_SPEED ); // .. with maximum speed while( SENSOR_GROUND>SENS2_MARK1 ) // Wait until it detected the ground msleep( 10 ); // motor_a_dir( rev ); // Reverse the motor and ... ds_rotation_set(&SENSOR_3,0x0000); // ... reset the rotation sensor to zero. while( SENSOR_UD < POS_UPPER ); // Wait until the bot will reached the msleep( 10 ); // upper position. motor_a_dir( fwd ); // Stop the sensor immediately at the msleep( 10 ); // upper position motor_a_speed( 0 ); // motor_a_dir( brake ); // } //------------------------------------------------------------------------------ // This function scans a slot and give the detected coin-height back to caller. //------------------------------------------------------------------------------ int ScanSlot() { int ground; // Variable for sensor value motor_a_dir( fwd ); // Move slot sensor down ... motor_a_speed( MAX_SPEED ); // ... with maximum speed while( SENSOR_GROUND>SENS2_MARK1 ) // Wait until the slot sensor detected a msleep( 10 ); // coin or the ground motor_a_dir( rev ); // Reverse the motor and move it up ground=SENSOR_UD; // Remember position of rotation sensor cputw(ground); // Display the value of the sensor and cputc_0( '_' ); // show '_' on the left display position while( SENSOR_UD < POS_UPPER ) // Wait until sensor will arive the upper msleep( 10 ); // position motor_a_dir( fwd ); // Stop the sensor immediately at the msleep( 10 ); // upper position motor_a_speed( 0 ); // motor_a_dir( brake ); // return ground; // Return the slot sensor position } //------------------------------------------------------------------------------ // This procedure move the whole slot sensor unit to the given slot position. //------------------------------------------------------------------------------ void MoveToPosition( int p ) { if( SENSOR_LR < p ) // If actual pos is less then destination { // motor_c_dir( rev ); // Move right with motor_c_speed( MAX_SPEED ); // maximum speed // while( SENSOR_LR < p ) // Wait until position is not reached msleep( 10 ); // // motor_c_dir( fwd ); // Stop the slot sensor unit immediately msleep( 10 ); // motor_c_speed( 0 ); // motor_c_dir( brake ); // } else // If actual pos is greater than destin. { // motor_c_dir( fwd ); // Move left with motor_c_speed( MAX_SPEED ); // maximum speed // while( SENSOR_LR > p ) // Wait until position is not reached msleep( 10 ); // // motor_c_dir( rev ); // Stop the slot sensor unit immediately msleep( 10 ); // motor_c_speed( 0 ); // motor_c_dir( brake ); // } } //------------------------------------------------------------------------------ // This procedure scans all slots for coins and calculate the amount and count // of coins at the slots. // // Procedure: Iterate on all slots with the following functions: // 1. Display the slot number // 2. Move detecting unit to position of slot // 3. Display the coin name of current slot // 4. Scan for coin height at current slot // 5. Calculate the number of coins and the amount of coins at slot // 6. Add amount and count to total amount and total count // 7. Display the values (depends on debug or nodebug mode) // debug: ####H nodebug: ###0n // ####n #0.00S // #0.00S //------------------------------------------------------------------------------ void ScanAllSlots() { int slot; // Variable for slot int height; // Varialbe for coin height at the slot total_sum=0; // Reset the total amount of coins total_num=0; // Reset the total count of coins for( slot=0; slot < NUMBER_OF_COINS; slot++ ) { // 1. Display the slot number cputs( "SLot " ); cputc_0( '1'+slot ); // 2. Move detecting unit to position of slot MoveToPosition( coinref[ slot ].position ); // 3. Display the coin name of current slot cputs( coinref[ slot ].name ); // 4. Scan for coin height at current slot height = ScanSlot() + coinref[ slot ].cordelta; // 5. Calculate the number of coins and the amount of coins at slot coinref[ slot ].count = height / coinref[ slot ].coin_height; coinref[ slot ].sum = coinref[ slot ].count * coinref[ slot ].value; // 6. Add amount and count to total amount and total count total_sum = total_sum + coinref[ slot ].sum; total_num = total_num + coinref[ slot ].count; // 7. Display the values (depends on debug or nodebug mode) if( DEBUG ) { cputw( height ); cputc_0( 'H' ); sleep( 2 ); cputw( coinref[ slot ].count ); cputc_0( 'n' ); sleep( 2 ); ShowValue( coinref[ slot ].sum ); cputc_0( 'S' ); sleep( 2 ); } else { cputw_decimal( coinref[ slot ].count ); cputc_0( 'n' ); msleep( 500 ); ShowValue( coinref[ slot ].sum ); cputc_0( 'S' ); msleep( 500 ); } } } //------------------------------------------------------------------------------ // This background function shows the value of the selected sensor. The sensor // will be selected by pressing the VIEW button at the RCX. It will increase the // value of variable "display". // // display displayed value // ------- --------------------------------------------------------------- // 0 No periodically refresh of display (normal function) // 1 Show value of rotation sensor S1 (vertical position of sensor) // 2 Show the raw value of sensor S2T and S2L // 3 Show value of rotation sensor S3 (relative position to legt end) //------------------------------------------------------------------------------ void Task_Displaying( int argc, char **argv ) { int display = 0; while( 1 ) // Repeat forever { if( PRESSED( dbutton(), BUTTON_VIEW ) ) // if VIEW pressed ... { // while( PRESSED( dbutton(), BUTTON_VIEW ) ) // ... wait of releasing msleep( 10 ); // of VIEW button if( display < 3 ) // If displaying value is less than display++; // 3, select next sensor. else // On the other side, display = 0; // select "no refresh of display" } switch( display ) // What will be displayed? { // case 0 : break; // No refresh of display // case 1 : cputw( ROTATION_1 ); // Display value of ROTATION_1 cputc_0( '1' ); // break; // // case 2 : cputw( SENSOR_2 ); // Display value of TOUCH_1 & LIGHT_1 cputc_0( '2' ); // break; // // case 3 : cputw( ROTATION_3 ); // Display value of ROTATION_3 cputc_0( '3' ); // break; // } // msleep( 50 ); // wait 0,05 seconds for next refresh } } //------------------------------------------------------------------------------ // This background function watched the light sensor for detecting a spinning // coin. It a coin passed this sensor, the global value "last_coin" will set to // the current system clock value (timestamp) and the RCX will quit it with a // little beep. //------------------------------------------------------------------------------ void Task_CoinDetect( int argc, char **argv ) { unsigned int v; // Sensor value while( 1 ) // Do forever { // v = SENSOR_2; // Get value of the sensor S2L // if( ( v > SENS2_MARK1 ) && // If the value is in the range of ( v < SENS2_MARK2 ) ) // detected coin ... { // last_coin = get_system_up_time();// ... get timestamp to variable dsound_play( Sound0 ); // and play a little beep } // // msleep( 10 ); // wait 0,01 secs for next scan } } //------------------------------------------------------------------------------ // Background process for main control. // // // //------------------------------------------------------------------------------ void Task_ProgControl( int argc, char **argv ) { int slot; // Variable for slot number time_t duration; // Variable for duration of process // Step 2. Sorting the coins // Step 2.1. Start conveyor belt and wait for first coin cputs( "StArt" ); // Show the activation of isolation motor_b_dir( fwd ); // unit ... motor_b_speed( MAX_SPEED ); // cputs( "COIn?" ); // ... and wait for first coin while( SENSOR_2 > SENS2_MARK2 ) // msleep( 10 ); // // Step 2.2. Wait until last coin was detected 5 secons ago cputs( "LASt?" ); // Wait for end of isolation unit... last_coin = get_system_up_time(); while( ( get_system_up_time()-last_coin ) < MAX_WAIT_COIN ) { cputc_0( '0'+( get_system_up_time()-last_coin ) / TICKS_PER_SEC ); msleep( 500 ); } cputs( "StOP " ); // .. and stop the isolation unit motor_b_dir( 0 ); // The sorting unit will also finished motor_b_speed( MAX_SPEED ); // it work and all coins are sorted. // Step 3. Checking the stacks/slots // Step 3.1. Move to every slot and check the stack height and // Step 3.2. Display the height of the current slot cputs( "Scan " ); // Starting the detecting unit .. ScanAllSlots(); // .. and wait for ending the process. // Stop the stopwatch and calculate the duration duration = get_system_up_time() - start_time; // Step 4. Show the result while( 1 ) { // Step 4.1. Show for every slot: Coin type, count of coins and amount for( slot=0; slot < NUMBER_OF_COINS; slot++ ) { cputs( coinref[ slot ].name ); sleep( 2 ); cputw_decimal( coinref[ slot ].count ); cputc_0( 'n' ); sleep( 2 ); ShowValue( coinref[ slot ].sum ); cputc_0( 'S' ); sleep( 2 ); } // Step 4.2. Show the total count and amount of coins cputw_decimal( total_num ); cputc_0( 'n' ); sleep( 2 ); ShowValue( total_sum ); cputc_0( 'T' ); sleep( 2 ); // Step 4.3. Show the duration of the detecting process ShowTime( duration ); cputc_0( 't' ); sleep( 2 ); } } //------------------------------------------------------------------------------ // Main Function. // // This function will initialize the bot, start the main control program and // wait until user will end the process by pressing the RUN button. //------------------------------------------------------------------------------ int main( ) { tid_t tid_Displaying; // Variable for background processes tid_t tid_CoinDetect; // tid_t tid_ProgControl; // while( PRESSED(dbutton(),BUTTON_RUN)) // Wait until the user will release msleep( 20 ); // the RUN button and wait 1 second sleep( 1 ); // for starting the process // Step 1. Preparing RCX // Step 1.1. Defining the sensors ds_active( &SENSOR_1 ); // SENSOR_LR ds_rotation_on( &SENSOR_1 ); // ds_rotation_set( &SENSOR_1, 0x0000 ); // ds_active( &SENSOR_2 ); // SENSOR_GROUND ds_active(&SENSOR_3 ); // SENSOR_UD ds_rotation_on( &SENSOR_3 ); // ds_rotation_set( &SENSOR_3, 0x0000 ); // // Step 1.2. Defining background tasks tid_Displaying = execi( &Task_Displaying, 0, NULL, 0, DEFAULT_STACK_SIZE ); tid_CoinDetect = execi( &Task_CoinDetect, 0, NULL, 0, DEFAULT_STACK_SIZE ); start_time = get_system_up_time(); // start stop watch // Step 1.3. Move to initial position cputs( "Init " ); // Show the start of initialization MoveToPosition( POS_1_CENT ); // Move to first slot and ... // Step 1.4. Check the ground value ResetGround(); // ... detect the ground for reset. // Step 2. - 4. will be managed at background process "Task_ProgControl" tid_ProgControl = execi( &Task_ProgControl, 0, NULL, 0, DEFAULT_STACK_SIZE ); while( ! PRESSED(dbutton(),BUTTON_RUN)) // Wait until user will interrupt msleep( 50 ); // the scanning process // Step 5. Reset the RCX // Step 5.1. Stop all background processes kill( tid_Displaying ); // Kill the started background kill( tid_CoinDetect ); // processes kill( tid_ProgControl ); // // Step 5.2. Reset the sensors ds_passive( &SENSOR_1 ); // Reset all sensor to passive mode ds_passive( &SENSOR_2 ); // ds_passive( &SENSOR_3 ); // return 0; // Signal normal end to RCX } //------------------------------------------------------------------------------ // CoinCountA.c - End of program //------------------------------------------------------------------------------