int main(void) { sysclk_init(); board_init(); configure_lcd(); configure_botao(); configure_adc(); configure_tc(); ili93xx_set_foreground_color(COLOR_BLACK); ili93xx_draw_string(10, 20, (uint8_t *)"14 - ADC"); /** Draw text, image and basic shapes on the LCD */ //ili93xx_set_foreground_color(COLOR_BLACK); //ili93xx_draw_string(10, 20, (uint8_t *)"14 - ADC"); while (1) { if(adc_value_new == 1) { refresh_lcd(adc_value_old); adc_value_new = 0; } } }
int main(void) { system_init(); //! [setup_init] configure_adc(); //! [setup_init] //! [main] //! [start_conv] adc_start_conversion(&adc_instance); //! [start_conv] //! [get_res] uint16_t result; do { /* Wait for conversion to be done and read out result */ } while (adc_read(&adc_instance, &result) == STATUS_BUSY); //! [get_res] //! [inf_loop] while (1) { /* Infinite loop */ } //! [inf_loop] //! [main] }
/** * set_up_therm_channel - enable thermal channel for conversion * @base_addr: index of free msic ADC channel * * Enable all the three channels for conversion * * Can sleep */ static int set_up_therm_channel(u16 base_addr) { int ret; /* Enable all the sensor channels */ ret = intel_msic_reg_write(base_addr, SKIN_SENSOR0_CODE); if (ret) return ret; ret = intel_msic_reg_write(base_addr + 1, SKIN_SENSOR1_CODE); if (ret) return ret; ret = intel_msic_reg_write(base_addr + 2, SYS_SENSOR_CODE); if (ret) return ret; /* Since this is the last channel, set the stop bit * to 1 by ORing the DIE_SENSOR_CODE with 0x10 */ ret = intel_msic_reg_write(base_addr + 3, (MSIC_DIE_SENSOR_CODE | 0x10)); if (ret) return ret; /* Enable ADC and start it */ return configure_adc(1); }
*/ int main(void) { sysclk_init(); board_init(); uint16_t i ; configure_LCD(); configure_dac(); configure_tc(1000); configure_adc(); resolucao = 100; deltaTeta = 2.0*PI/((float)resolucao); valorMedio = MAX_AMPLITUDE_ANAG/2.0; ili93xx_draw_pixmap(0, ILI93XX_LCD_HEIGHT-100-1, 240-1, 100-1, &image_data_maua[0]); while (1) { }
static int set_up_therm_channel(u16 base_addr) { int ret; ret = intel_msic_reg_write(base_addr, SKIN_SENSOR0_CODE); if (ret) return ret; ret = intel_msic_reg_write(base_addr + 1, SKIN_SENSOR1_CODE); if (ret) return ret; ret = intel_msic_reg_write(base_addr + 2, SYS_SENSOR_CODE); if (ret) return ret; ret = intel_msic_reg_write(base_addr + 3, (MSIC_DIE_SENSOR_CODE | 0x10)); if (ret) return ret; return configure_adc(1); }
/* Initialize the ADC for reading micbias values. Can sleep. */ static int sn95031_initialize_adc(struct snd_soc_codec *sn95031_codec) { int base_addr, chnl_addr; int value; int channel_index; /* Index of the first channel in which the stop bit is set */ channel_index = find_free_channel(sn95031_codec); if (channel_index < 0) { pr_err("No free ADC channels"); return channel_index; } base_addr = SN95031_ADC_CHNL_START_ADDR + channel_index; if (!(channel_index == 0 || channel_index == SN95031_ADC_LOOP_MAX)) { /* Reset stop bit for channels other than 0 and 12 */ value = snd_soc_read(sn95031_codec, base_addr); /* Set the stop bit to zero */ snd_soc_write(sn95031_codec, base_addr, value & 0xEF); /* Index of the first free channel */ base_addr++; channel_index++; } /* Since this is the last channel, set the stop bit to 1 by ORing the DIE_SENSOR_CODE with 0x10 */ snd_soc_write(sn95031_codec, base_addr, SN95031_AUDIO_DETECT_CODE | 0x10); chnl_addr = SN95031_ADC_DATA_START_ADDR + 2 * channel_index; pr_debug("mid_initialize : %x", chnl_addr); configure_adc(sn95031_codec, 1); return chnl_addr; }
int main(void) { system_init(); //! [setup_init] configure_adc(); configure_adc_callbacks(); //! [setup_init] //! [main] //! [enable_global_interrupts] system_interrupt_enable_global(); //! [enable_global_interrupts] //! [start_adc_job] adc_read_buffer_job(&adc_instance, adc_result_buffer, ADC_SAMPLES); //! [start_adc_job] //! [job_complete_poll] while (adc_read_done == false) { /* Wait for asynchronous ADC read to complete */ } //! [job_complete_poll] //! [inf_loop] while (1) { /* Infinite loop */ } //! [inf_loop] //! [main] }
int main(void) { system_clock_config(CLOCK_RESOURCE_XO_26_MHZ, CLOCK_FREQ_26_MHZ); //! [setup_init] configure_adc(); //! [setup_init] //! [main] //! [get_res] uint16_t result; do { /* Wait for conversion to be done and read out result */ } while (adc_read(CONF_ADC_INPUT_CH, &result) == STATUS_BUSY); //! [get_res] //! [inf_loop] while (1) { /* Infinite loop */ } //! [inf_loop] //! [main] }
void main(void) { init_pins(); init_oscillator(); SPI1_Initialize(); float temp = 0; // Set all pins RD1-7 to inputs, RD0 (MSB is set to output) //TRISD = 0b11111110; // RC2 is PWM pin TRISCbits.RC2 = 0; configure_adc(); configure_pwm(); int ticks = 0; while (1) { MAX_7221_INIT(); temp = get_temperature(0); set_fan_speed(temp); if(ticks % 125 == 0) { MAX_7221_WRITE_FLOAT(temp, 3); ticks = 0; } ticks++; } }
/** * mid_thermal_suspend - suspend routine * @dev: device structure * * mid thermal suspend implements the suspend functionality * by stopping the ADC. Can sleep. */ static int mid_thermal_suspend(struct device *dev) { /* * This just stops the ADC and does not disable it. * temporary workaround until we have a generic ADC driver. * If 0 is passed, it disables the ADC. */ return configure_adc(0); }
/** * mid_thermal_probe - mfld thermal initialize * @pdev: platform device structure * * mid thermal probe initializes the hardware and registers * all the sensors with the generic thermal framework. Can sleep. */ static int mid_thermal_probe(struct platform_device *pdev) { static char *name[MSIC_THERMAL_SENSORS] = { "skin0", "skin1", "sys", "msicdie" }; int ret; int i; struct platform_info *pinfo; pinfo = kzalloc(sizeof(struct platform_info), GFP_KERNEL); if (!pinfo) return -ENOMEM; /* Initializing the hardware */ ret = mid_initialize_adc(&pdev->dev); if (ret) { dev_err(&pdev->dev, "ADC init failed"); kfree(pinfo); return ret; } /* Register each sensor with the generic thermal framework*/ for (i = 0; i < MSIC_THERMAL_SENSORS; i++) { struct thermal_device_info *td_info = initialize_sensor(i); if (!td_info) { ret = -ENOMEM; goto err; } pinfo->tzd[i] = thermal_zone_device_register(name[i], 0, 0, td_info, &tzd_ops, NULL, 0, 0); if (IS_ERR(pinfo->tzd[i])) { kfree(td_info); ret = PTR_ERR(pinfo->tzd[i]); goto err; } } pinfo->pdev = pdev; platform_set_drvdata(pdev, pinfo); return 0; err: while (--i >= 0) { kfree(pinfo->tzd[i]->devdata); thermal_zone_device_unregister(pinfo->tzd[i]); } configure_adc(0); kfree(pinfo); return ret; }
/** * mid_thermal_remove - mfld thermal finalize * @dev: platform device structure * * MLFD thermal remove unregisters all the sensors from the generic * thermal framework. Can sleep. */ static int mid_thermal_remove(struct platform_device *pdev) { int i; struct platform_info *pinfo = platform_get_drvdata(pdev); for (i = 0; i < MSIC_THERMAL_SENSORS; i++) { kfree(pinfo->tzd[i]->devdata); thermal_zone_device_unregister(pinfo->tzd[i]); } /* Stop the ADC */ return configure_adc(0); }
int main(void) { sysclk_init(); board_init(); configure_lcd(); configure_botao(); configure_adc(); configure_tc(); /** Draw text, image and basic shapes on the LCD */ ili93xx_set_foreground_color(COLOR_BLACK); ili93xx_draw_string(10, 20, (uint8_t *)"14 - ADC"); ili93xx_draw_filled_circle(120,160,60); ili93xx_set_foreground_color(COLOR_WHITE); ili93xx_draw_filled_circle(120,160,55); while (1) { }
/** * \brief Function for calibration the DAC using the internal ADC * * This function will calibrate the DAC using the internal ADC, please be aware * that signals will be outputted on the DAC pins. * * When calibrating always start with the offset then do gain calibration. * */ static void dac_calibrate(void) { /* Configure the DAC output pins */ configure_pins(); /* Configure the DAC for this calibration sequence */ configure_dac(); /* Configure the ADC for this calibration sequence */ configure_adc(); /* Calibrate offset and gain for DAC CH0 */ dac_calibrate_offset(DAC_CH0); dac_calibrate_gain(DAC_CH0); /* Calibrate offset and gain for DAC CH1 */ dac_calibrate_offset(DAC_CH1); dac_calibrate_gain(DAC_CH1); adc_disable(&CALIBRATION_ADC); }
void configure_adc_default(UINT8 ain){ configure_adc( 0x2, // Select a V_DD_AN/2 (1.65) reference 0x8, // Now collect 256 samples at a time. // Theoretical result has 20-bit precision. // ADC will automatically right shift // 6 times, so result has 16-bit precision. // Total sampling time length = (SAMPLEN+1)*(Clk_ADC/2) 0x1, // Set sampling time to 1 adc clock cycle? 0x2, // Relative to main clock, have adc clock // run 8 times slower 0x1, // For averaging more than 2 samples, // change RESSEL (0x1 for 16-bit) 0xF, // Since reference is 1/2, // set gain to 1/2 to keep largest // input voltage range (expected input // will be 0 - 3.3V) 0x18, // Not using the negative for differential, so ground it. ain // Map the adc to analog pin ain ); }
int main(void) { system_init(); delay_init(); //! [setup_init] configure_adc(); //! [setup_init] //! [main] //! [start_conv] adc_start_conversion(&adc_instance); //! [start_conv] //! [get_res] uint16_t result=0; configure_console(); //! [get_res] //! [inf_loop] while (1) { /* Infinite loop */ //adc_read(&adc_instance, &result); do { /* Wait for conversion to be done and read out result */ } while (adc_read(&adc_instance, &result) == STATUS_BUSY); printf("The result is %d\n",result); uint32_t far = 9.0/5.0*((float)result*.0002441406*6.0/.01)+32.0; printf(" The temp is %d", far); adc_clear_status(&adc_instance,adc_get_status(&adc_instance)); adc_start_conversion(&adc_instance); delay_ms(500); } //! [inf_loop] //! [main] }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_client_process, ev, data) { static struct etimer periodic; static struct ctimer backoff_timer; #if WITH_COMPOWER static int print = 0; #endif PROCESS_BEGIN(); PROCESS_PAUSE(); set_global_address(); PRINTF("UDP client process started\n"); print_local_addresses(); /* new connection with remote host */ client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); if(client_conn == NULL) { PRINTF("No UDP connection available, exiting the process!\n"); PROCESS_EXIT(); } udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); PRINTF("Created a connection with the server "); PRINT6ADDR(&client_conn->ripaddr); PRINTF(" local/remote port %u/%u\n", UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport)); // printf("%d \n", CLOCK_SECOND); #if WITH_COMPOWER powertrace_sniff(POWERTRACE_ON); #endif configure_adc(); //etimer_set(&periodic, SEND_INTERVAL); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { // tcpip_handler(); } //if(etimer_expired(&periodic)) { //PRINTF("Timer Expired "); //etimer_reset(&periodic); //} if(ev==event_data_ready) { /*if(counter == 33) { memmove(buf+2, buffer, 66); counter = 0; ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL); //printf("Counter %d \n",counter); }*/ #if WITH_COMPOWER if (print == 0) { powertrace_print("#P"); } if (++print == 3) { print = 0; } #endif } } PROCESS_END(); }
static int mid_thermal_suspend(struct platform_device *pdev, pm_message_t mesg) { return configure_adc(0); }
/** * \brief The main application. */ int main(void) { uint8_t i; uint8_t temperature[BUFFER_SIZE]; uint8_t light[BUFFER_SIZE]; char value_disp[5]; uint32_t adc_value; uint32_t light_value; double temp; /* Initialize clocks. */ sysclk_init(); /* Initialize GPIO states. */ board_init(); /* Configure ADC for light sensor. */ configure_adc(); /* Initialize at30tse. */ at30tse_init(); /* Configure IO1 buttons. */ configure_buttons(); /* Initialize SPI and SSD1306 controller. */ ssd1306_init(); ssd1306_clear(); /* Clear internal buffers. */ for (i = 0; i < BUFFER_SIZE; ++i) { temperature[i] = 0; light[i] = 0; } /* Show the start info. */ multi_language_show_start_info(); /* Wait 3 seconds to show the above message. */ delay_s(3); /* Check for valid firmware in SD card. */ check_valid_firmware(); while (true) { /* Set the trigger and jump to bootloader */ if (reset_flag) { jump_to_bootloader(); } /* Refresh page title only if necessary. */ if (app_mode_switch > 0) { app_mode = (app_mode + 1) % 3; /* Clear screen. */ ssd1306_clear(); ssd1306_set_page_address(0); ssd1306_set_column_address(0); if (app_mode == 0) { /* Temperature mode. */ ioport_set_pin_level(OLED1_LED1_PIN, OLED1_LED1_ACTIVE); ioport_set_pin_level(OLED1_LED2_PIN, !OLED1_LED2_ACTIVE); ioport_set_pin_level(OLED1_LED3_PIN, !OLED1_LED3_ACTIVE); multi_language_show_temperature_info(); } else if (app_mode == 1) { /* Light mode. */ ioport_set_pin_level(OLED1_LED2_PIN, OLED1_LED2_ACTIVE); ioport_set_pin_level(OLED1_LED1_PIN, !OLED1_LED1_ACTIVE); ioport_set_pin_level(OLED1_LED3_PIN, !OLED1_LED3_ACTIVE); multi_language_show_light_info(); } else { /* SD mode. */ ioport_set_pin_level(OLED1_LED3_PIN, OLED1_LED3_ACTIVE); ioport_set_pin_level(OLED1_LED1_PIN, !OLED1_LED1_ACTIVE); ioport_set_pin_level(OLED1_LED2_PIN, !OLED1_LED2_ACTIVE); sd_listing_pos = 0; /* Show SD card info. */ display_sd_info(); } app_mode_switch = 0; } /* Shift graph buffers. */ for (i = 0; i < (BUFFER_SIZE - 1); ++i) { temperature[i] = temperature[i + 1]; light[i] = light[i + 1]; } /* Get temperature. */ if (at30tse_read_temperature(&temp) == TWI_SUCCESS) { /* Don't care about negative temperature. */ if (temp < 0) { temp = 0; } /* Update temperature for display. */ /* Note: rescale to 0~24 for better rendering. */ if (temp > 40) { temperature[BUFFER_SIZE - 1] = 24; } else { temperature[BUFFER_SIZE - 1] = (uint8_t)temp * 24 / 40; } } else { /* Error print zero values. */ temperature[BUFFER_SIZE - 1] = 0; } /* Get light sensor information. */ /* Rescale to 0~24 for better rendering. */ adc_start_software_conversion(ADC); adc_value = adc_channel_get_value(ADC, ADC_CHANNEL_0); light[BUFFER_SIZE - 1] = 24 - adc_value * 24 / 1024; if (app_mode == 0) { /* Display temperature in text format. */ sprintf(value_disp, "%d", (uint8_t)temp); ssd1306_set_column_address(98); ssd1306_write_command(SSD1306_CMD_SET_PAGE_START_ADDRESS(0)); ssd1306_write_text(" "); /* Avoid character overlapping. */ if (temp < 10) { ssd1306_clear_char(); } ssd1306_write_text(value_disp); /* Display degree symbol. */ ssd1306_write_data(0x06); ssd1306_write_data(0x06); ssd1306_write_text("c"); /* Refresh graph. */ ssd1306_draw_graph(0, 2, BUFFER_SIZE, 2, temperature); } else if (app_mode == 1) { light_value = 100 - (adc_value * 100 / 1024); sprintf(value_disp, "%lu", light_value); ssd1306_set_column_address(98); ssd1306_write_command(SSD1306_CMD_SET_PAGE_START_ADDRESS(0)); ssd1306_write_text(" "); /* Avoid character overlapping. */ if (light_value < 10) { ssd1306_clear_char(); } ssd1306_write_text(value_disp); ssd1306_write_text("%"); /* Avoid character overlapping. */ if (light_value < 100) { ssd1306_clear_char(); } /* Refresh graph. */ ssd1306_draw_graph(0, 2, BUFFER_SIZE, 2, light); } else { /** * Refresh screen if card was inserted/removed or * browsing content. */ if (sd_update == 1) { /* Clear screen. */ ssd1306_clear(); ssd1306_set_page_address(0); ssd1306_set_column_address(0); if (sd_listing_pos == 0) { /* Show SD card info. */ display_sd_info(); } else { /* List SD card files. */ display_sd_files_unicode(); } sd_update = 0; } } /* Wait and stop screen flickers. */ delay_ms(150); if (app_mode_switch == 0) { pio_enable_interrupt(OLED1_PIN_PUSHBUTTON_1_PIO, OLED1_PIN_PUSHBUTTON_1_MASK); } if (sd_update == 0) { pio_enable_interrupt(OLED1_PIN_PUSHBUTTON_2_PIO, OLED1_PIN_PUSHBUTTON_2_MASK); pio_enable_interrupt(OLED1_PIN_PUSHBUTTON_3_PIO, OLED1_PIN_PUSHBUTTON_3_MASK); } } }
/** * \brief Main Application Routine \n * - Initialize the system clocks \n * NOTE: The clock should be configured in conf_clock.h \n * - Configure port pins (PA14 and PA16) are used here \n * - Enable Global Interrupt \n * - Configure and enable USART \n * - Configure and enable ADC \n * - Configure and enable DMAC and EVSYS if DMAC mode is chosen \n * - Start first ADC conversion \n * - Count idle loop count in forever loop \n */ int main(void) { /* Initialize system clocks */ system_init(); #if defined(ENABLE_PORT_TOGGLE) /* Configure PORT pins PA14 and PA16 are configured here * NOTE: Use oscilloscope to probe the pin. */ configure_port(); #endif /* ENable Global interrupt */ system_interrupt_enable_global(); /* Start SysTick Timer */ systick_init(); /* Configure SERCOM - USART */ configure_usart(); /* Configure and enable ADC */ configure_adc(); /* Configure and enable EVSYS */ configure_event(); /* Configure and enable DMA channel and descriptor */ configure_dma(); /* Get the time stamp 1 before starting ADC transfer */ time_stamp1 = SysTick->VAL; /* * Trigger first ADC conversion through software. * NOTE: In case of using DMA, further conversions are triggered through * event generated when previous ADC result is transferred to destination * (can be USART DATA register [or] RAM buffer). * When DMA is not used, further conversions are triggered via software in * ADC handler after each result ready. */ adc_start_conversion(&adc_instance); while (1){ #if defined (ENABLE_PORT_TOGGLE) /* Use oscilloscope to probe the pin. */ port_base->OUTTGL.reg = (1UL << PIN_PA16 % 32 ); #endif /* Increment idle count whenever application reached while(1) loop */ idle_loop_count++; /* * Check if 1024 bytes transfer is done in either case (I.e. with or without * using DMA. * 'adc_conv_done' flag is set to true in the ADC handler once * 'adc_sample_count' reaches BLOCK_COUNT. * 'adc_dma_transfer_is_done' is set to true once DMA transfer is done * in DMA call back for channel zero when 'ADC_DMAC_USART' is chosen. * When choosing ADC_DMAC_MEM_MEM_USART mode, 'adc_dma_transfer_is_done' * is set to true in DMA channel call back for channel 2. * DMA channel is disabled once reaching BLOCK_COUNT (with DMA cases). * ADC is disabled once reaching BLOBK_COUNT samples (without DMA cases). */ if (adc_dma_transfer_is_done == true){ /* * Calculate number of cycles taken from the time stamp * taken before start of the conversion and after 1024 transfer * is completed. * NOTE: This value in relation to the idle_loop_count is * used in calculating CPU usage. */ cycles_taken = calculate_cycles_taken(time_stamp1,time_stamp2); /* Write the CPU cycles taken on USART */ usart_write_buffer_wait(&usart_instance, (uint8_t *)&cycles_taken, sizeof(cycles_taken)); /* Print idle loop count on USART */ usart_write_buffer_wait(&usart_instance,(uint8_t *)&idle_loop_count, sizeof(idle_loop_count)); /* * Enter into forever loop as all transfers are completed and * DMAC/ADC is disabled */ while(1); } } }//end of main
int main(void) { uint8_t i; uint8_t temperature[BUFFER_SIZE]; uint8_t light[BUFFER_SIZE]; uint8_t value_disp[5]; uint32_t adc_value; double temp; // Initialize clocks. sysclk_init(); // Initialize GPIO states. board_init(); // Configure ADC for light sensor. configure_adc(); // Initialize at30tse. at30tse_init(); // Configure IO1 buttons. configure_buttons(); // Initialize SPI and SSD1306 controller. ssd1306_init(); ssd1306_clear(); // Clear internal buffers. for (i = 0; i < BUFFER_SIZE; ++i) { temperature[i] = 0; light[i] = 0; } while (true) { /* Refresh page title only if necessary. */ if (app_mode_switch > 0) { app_mode = app_mode_switch - 1; // Clear screen. ssd1306_clear(); ssd1306_set_page_address(0); ssd1306_set_column_address(0); /* Temperature mode. */ if (app_mode == 0) { ioport_set_pin_level(IO1_LED1_PIN, IO1_LED1_ACTIVE); ioport_set_pin_level(IO1_LED2_PIN, !IO1_LED2_ACTIVE); ioport_set_pin_level(IO1_LED3_PIN, !IO1_LED3_ACTIVE); ssd1306_write_text("Temperature sensor:"); } /* Light mode. */ else if (app_mode == 1) { ioport_set_pin_level(IO1_LED2_PIN, IO1_LED2_ACTIVE); ioport_set_pin_level(IO1_LED1_PIN, !IO1_LED1_ACTIVE); ioport_set_pin_level(IO1_LED3_PIN, !IO1_LED3_ACTIVE); ssd1306_write_text("Light sensor:"); } /* SD mode. */ else { ioport_set_pin_level(IO1_LED3_PIN, IO1_LED3_ACTIVE); ioport_set_pin_level(IO1_LED1_PIN, !IO1_LED1_ACTIVE); ioport_set_pin_level(IO1_LED2_PIN, !IO1_LED2_ACTIVE); display_sd_info(); } app_mode_switch = 0; } // Shift graph buffers. for (i = 0; i < BUFFER_SIZE - 1; ++i) { temperature[i] = temperature[i + 1]; light[i] = light[i + 1]; } // Get temperature in a range from 0 to 40 degrees. if (at30tse_read_temperature(&temp) == TWI_SUCCESS) { // Don't care about negative temperature. if (temp < 0) temp = 0; // Update temperature for display. // Note: -12 in order to rescale for better rendering. if (temp < 12) temperature[BUFFER_SIZE - 1] = 0; else temperature[BUFFER_SIZE - 1] = temp - 12; } else { // Error print zero values. temperature[BUFFER_SIZE - 1] = 0; } // Get light sensor information. // Rescale for better rendering. adc_start(ADC); adc_value = adc_get_channel_value(ADC, ADC_CHANNEL_4); light[BUFFER_SIZE - 1] = 24 - adc_value * 24 / 4096; // Print temperature in text format. if (app_mode == 0) { sprintf(value_disp, "%d", (uint8_t)temp); ssd1306_set_column_address(95); ssd1306_write_command(SSD1306_CMD_SET_PAGE_START_ADDRESS(0)); ssd1306_write_text(" "); ssd1306_write_text(value_disp); // Display degree symbol. ssd1306_write_data(0x06); ssd1306_write_data(0x06); ssd1306_write_text("c"); // Refresh graph. ssd1306_draw_graph(0, 1, BUFFER_SIZE, 3, temperature); } else if (app_mode == 1) { sprintf(value_disp, "%lu", 100 - (adc_value * 100 / 4096)); ssd1306_set_column_address(98); ssd1306_write_command(SSD1306_CMD_SET_PAGE_START_ADDRESS(0)); ssd1306_write_text(" "); ssd1306_write_text(value_disp); ssd1306_write_text("%"); // Refresh graph. ssd1306_draw_graph(0, 1, BUFFER_SIZE, 3, light); } else { // Is card has been inserted or removed? if (sd_status_update == 1) { // Clear screen. ssd1306_clear(); ssd1306_set_page_address(0); ssd1306_set_column_address(0); // Show SD card info. display_sd_info(); sd_status_update = 0; } } /* Wait and stop screen flickers. */ delay_ms(50); } }