The LED is connected to pin 0 on PORTD which is controlled by values from the ADC. The LED is actually representing a vacuum pump, so when the pressure sensor that is connected to the ADC passes a high threshold that will turn off the motor (pin to low) and if the ADC passes a low threshold, the motor will turn on (pin high). This will keep a vacuum in the tank between these two thresholds.
#include <avr/io.h>
#include "MrLCD.h"
#include <avr/interrupt.h>
int static volatile InchesOfHg = 0;
int main(void)
{
InitializeMrLCD();
Send_A_StringToMrLCDWithLocation(1, 1, "Inches of Hg:");
DDRD |= 1<<PIND0;
ADCSRA |= 1<<ADPS2;
ADMUX |= 1<<REFS0;
ADCSRA |= 1<<ADIE;
ADCSRA |= 1<<ADEN;
sei();
ADCSRA |= 1<<ADSC;
uint8_t enoughVacuum = 0;
while (1)
{
if (InchesOfHg > 25) enoughVacuum = 1;
if (InchesOfHg < 15) enoughVacuum = 0;
if (enoughVacuum == 0 && bit_is_clear(PORTD, PIND0)) PORTD |= 1<<PIND0;
if (enoughVacuum == 1 && bit_is_set(PORTD, PIND0)) PORTD &= ~(1<<PIND0);
}
}
ISR(ADC_vect)
{
uint8_t theLowADC = ADCL;
uint16_t TenBitResult = ADCH<<8 | theLowADC;
InchesOfHg = -0.0376 * TenBitResult + 35.532;
Send_An_IntegerToMrLCD(15, 1, InchesOfHg, 4);
ADCSRA |= 1<<ADSC;
}
Comments and Additional Information
Have some code to share? Or additional information? Respond here:
You need to be logged in to save a response on this page. The response must be constructive, helpful, supplimentary or to correct the existing video, code or narrative content.