This document discusses object counting using different programming languages and platforms like CodeVision, ARM, AVR-GCC, Arduino, and Raspberry Pi with Scratch. It provides code examples for object counting using a button press sensor in CodeVision, ARM, AVR-GCC, and Arduino. The CodeVision, ARM, and AVR-GCC code examples check the button sensor, add a delay if pressed, then count when released. The Arduino code prints the count to the serial monitor.
This document discusses object counting using different programming languages and platforms like CodeVision, ARM, AVR-GCC, Arduino, and Raspberry Pi with Scratch. It provides code examples for object counting using a button press sensor in CodeVision, ARM, AVR-GCC, and Arduino. The CodeVision, ARM, and AVR-GCC code examples check the button sensor, add a delay if pressed, then count when released. The Arduino code prints the count to the serial monitor.
EMBEDDED SYSTEM – POLITEKNIK ELEKTRONIKA NEGERI SURABAYA 5
Codes void delay(unsigned int periode) { CodeVision //perhitungan kasar, untuk //kristal 4.0MHz void main() //tundaan yang dihasilkan { //adalah: periode x ~1ms unsigned char counter; //gunakan debugger untuk while(1) //merancang waktu { unsigned int i,j; PORTD = counter; for(j=0;j<330;j++) if (PINC.0==0){ { delay(10); for(i=0;i<periode;i++) {}; if (PINC.0==0){ } while (PINC.0==0); } counter++; } } } //loop-forever //tampilkan nilai counter ke LED //bila saklar diaktifkan //tunda 10 ms //cek saklar kembali //tunggu sampai dilepas //tambah counter dengan 1 } EMBEDDED SYSTEM – POLITEKNIK ELEKTRONIKA NEGERI SURABAYA 6 Codes uint8_t sensorDetected(void){ uint8_t FlagDetect=0; ARM if(HAL_GPIO_ReadPin(pbOk_GPIO_Port,pbOk_Pin)== GPIO_PIN_RESET) { HAL_Delay(20); if(HAL_GPIO_ReadPin(pbOk_GPIO_Port,pbOk_Pin)== GPIO_PIN_RESET) { while(HAL_GPIO_ReadPin(pbOk_GPIO_Port,pbOk_Pin)== GPIO_PIN_RESET); FlagDetect=1; } } return FlagDetect; }
EMBEDDED SYSTEM – POLITEKNIK ELEKTRONIKA NEGERI SURABAYA 7