This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| et:examples:sensor:photoresistor [2015/02/27 18:52] – mikk | et:examples:sensor:photoresistor [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ~~PB~~ | + | < |
| ====== Fototakisti ====== | ====== Fototakisti ====== | ||
| Line 41: | Line 41: | ||
| VT935G andur ei olegi tegelikult mõeldud konkreetseks mõõteseadmeks, | VT935G andur ei olegi tegelikult mõeldud konkreetseks mõõteseadmeks, | ||
| - | Käesolev harjutus on aga natukese keerulisem, kuna leitakse andurile | + | Käesolev harjutus on aga natukese keerulisem, kuna leitakse andurile |
| [{{ : | [{{ : | ||
| Line 82: | Line 82: | ||
| <code c> | <code c> | ||
| - | // Kodulabori fototakisti näidisprogramm. | + | // Kodulabori fototakisti näidisprogramm |
| // LCD ekraanil kuvatakse ligikaudne valgustustihedus luksides | // LCD ekraanil kuvatakse ligikaudne valgustustihedus luksides | ||
| #include < | #include < | ||
| Line 100: | Line 100: | ||
| lcd_gfx_init(); | lcd_gfx_init(); | ||
| - | //LCD taustavalguse tööle seadmine | + | // LCD taustavalguse tööle seadmine |
| lcd_gfx_backlight(true); | lcd_gfx_backlight(true); | ||
| | | ||
| Line 116: | Line 116: | ||
| // Lõputu tsükkel | // Lõputu tsükkel | ||
| - | while (true) | + | while (1) |
| { | { | ||
| - | // Fototakisti | + | // Fototakisti |
| adc_value = adc_get_average_value(13, | adc_value = adc_get_average_value(13, | ||
| - | // Kodulabor | + | // Kodulabor |
| - | // adc_value = adc_get_average_value(1, | + | // |
| // Pinge arvutamine ADC sisendis | // Pinge arvutamine ADC sisendis | ||
| // Kodulabor II | // Kodulabor II | ||
| - | // voltage = 5.0 * ((double)adc_value / 1024.0); | + | //voltage = 5.0 * ((double)adc_value / 1024.0); |
| // Kodulabor III | // Kodulabor III | ||
| voltage = 2.0625 * ((double)adc_value / 2048.0); | voltage = 2.0625 * ((double)adc_value / 2048.0); | ||
| Line 131: | Line 131: | ||
| // Fototakisti takistuse arvutamine pingejaguris | // Fototakisti takistuse arvutamine pingejaguris | ||
| // Kodulabor II | // Kodulabor II | ||
| - | // resistance = (10.0 * 5.0) / voltage - 10.0; | + | // |
| // Kodulabor III | // Kodulabor III | ||
| resistance = (33.0) / voltage - 10.0; | resistance = (33.0) / voltage - 10.0; | ||
| - | // Valgustustiheduse | + | // Valgustustiheduse |
| illuminance = 255.84 * pow(resistance, | illuminance = 255.84 * pow(resistance, | ||
| - | // muutuja | + | // Muutuja |
| + | // eraldi täisarvuliseks | ||
| int8_t illu = illuminance; | int8_t illu = illuminance; | ||
| int16_t illudp = trunc((illuminance - illu) * 1000); | int16_t illudp = trunc((illuminance - illu) * 1000); | ||