Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Pawel Miron , Mateusz Bucko, projekt 1
- byte handle = 0; // file handle
- #define FILE_NAME "scannerdata15.dat"
- // The file size is made small so it will fill up quickly.
- #define FILE_SIZE 10024
- void rtn_code_out(const unsigned int code)
- {
- TextOut(0, LCD_LINE2, "code ");
- TextOut(50, LCD_LINE2, FormatNum("%04x", code));
- }
- void shutdown(const int delay)
- {
- if (handle) CloseFile(handle);
- // Get user's attention.
- //PlayTone(TONE_C5, SEC_1);
- // Give the user time to read screen messages.
- Wait(200);
- Stop(true);
- }
- void open_for_write()
- {
- unsigned int file_size = FILE_SIZE;
- handle = 0;
- // Start with the assumptions the file doesn't exist and needs to be created.
- unsigned int rtn_code = CreateFile(FILE_NAME, file_size, handle);
- // If the file already exists, open it with the intent of adding to the data
- // that is already there.
- if (rtn_code == LDR_FILEEXISTS)
- rtn_code = OpenFileAppend(FILE_NAME, file_size, handle);
- // Return code handling
- switch (rtn_code)
- {
- case LDR_SUCCESS:
- return;
- case LDR_FILEISFULL:
- TextOut(0, LCD_LINE1, "file is full ");
- break;
- default:
- // Unanticipated exception.
- TextOut(0, LCD_LINE1, "write open ");
- rtn_code_out(rtn_code);
- break;
- }
- }
- void write_recd(const int recd)
- {
- unsigned int cnt = 8;
- string str = NumToStr(recd);
- unsigned int rtn_code = WriteLnString(handle, str, cnt);
- // Return code handling
- if (rtn_code != LDR_SUCCESS)
- {
- switch (rtn_code)
- {
- case LDR_EOFEXPECTED:
- TextOut(0, LCD_LINE1, "no more space ");
- break;
- default:
- // Unanticipated exception.
- TextOut(0, LCD_LINE1, "write failed ");
- rtn_code_out(rtn_code);
- break;
- }
- shutdown(SEC_8);
- }
- }
- void clearLcd() {
- ClearLine(LCD_LINE3);
- ClearLine(LCD_LINE4);
- ClearLine(LCD_LINE5);
- ClearLine(LCD_LINE6);
- }
- int lastLastValue = 0;
- int lastValue = 0;
- int numberOfLines = 0;
- int growing = 0;
- void scan() {
- clearLcd();
- int raw[4];
- int ex[4];
- int raw2[4];
- int norm[4];
- int scaled[4];
- ReadSensorColorRaw(IN_1, raw); // 0, 1024
- ReadSensorColorEx(IN_1, ex, raw2, norm, scaled);
- if(lastValue - norm[0] > 10 || lastValue - norm[0] < -10) {
- lastLastValue = lastValue;
- lastValue = norm[0];
- }
- if (growing == 0) {
- if (lastValue< lastLastValue) {
- growing=1;
- numberOfLines++;
- }
- } else {
- if (lastValue> lastLastValue) {
- growing=0;
- numberOfLines++;
- }
- }
- TextOut(0, LCD_LINE6, "L"); //ight intensity
- NumOut(50, LCD_LINE6,lastValue);
- write_recd(lastValue);
- write_recd(numberOfLines);
- //TextOut(0, LCD_LINE6, "L"); //ight intensity
- //NumOut(50, LCD_LINE6,norm[0]);
- //write_recd(norm[0]);
- }
- task engine() {
- while(true) {
- //RotateMotor(OUT_A, 10, 5);
- OnFwd(OUT_A, 10);
- }
- }
- task scanner() {
- while(true) {
- scan();
- //Wait(1000);
- }
- }
- //135 pomiarow / 1s
- task timer() {
- long time = CurrentTick();
- long endt = 12000;
- while(CurrentTick() - time < endt);
- shutdown(SEC_8);
- }
- task main()
- {
- open_for_write();
- //SetSensor(IN_1, SENSOR_COLORFULL); // rgb
- SetSensorColorFull(IN_1);
- Precedes(engine, scanner, timer);
- TextOut(0, LCD_LINE1, "Linie");
- NumOut(50, LCD_LINE2, numberOfLines);
- //Wait(20000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement