[ Log In ]
10K timmer potentiometer

10K Trimmer Potentiometer (Through Hole)

$0.85
Qty:
20k trimmer potentiometer

20K Through Hole Trimmer Potentiometer

$0.85
Qty:
Top view of 50k Trimmer variable resistor potentiometer

50K Trimmer Through Hole

$0.85
Qty:
50K Potentiometer Panel Mount

50K Potentiometer Panel Mount (Non Trimmer)

$1.49
Qty:
Small red knob for potentiometer

Small Knob for Potentiometer - Black with Red Cap

$0.94
Qty:
Potentiometer with adjustable knob.

50K Potentiometer Panel Mount (Non Trimmer) With Knob

$2.45
Qty:
A 5K Rotary Potentiometer shown with a pencil for scale.

5K Potentiometer - Rotary

$0.95
Qty:

16x2 LCD (Liquid Crystal Display)

16x2 LCD (Liquid Crystal Display)

$12.50
Qty:
Flex Sensor - Sensing Bending and Displacement

55.37mm (2.18 Inch) Flex Sensor

$8.50
Qty:

Result: Applying the Slope Intercept Formula to Adjust the ADC Value for Trimmer Potentiometers Showing on the LCD

The code in the ADC channels are updated to reflect the slope intercept formula so the trimmer potentiometers show a range or 0 - 33 rather than the raw ADC result of 0 - 1023.
#include <avr/io.h>
#include "MrLCD.h"
#include <avr/interrupt.h>

int static volatile InchesOfHg, High, Low = 0;

int main(void)
{
InitializeMrLCD();
Send_A_StringToMrLCDWithLocation(1, 1, "Inches of Hg:");
Send_A_StringToMrLCDWithLocation(1, 2, "H: L:");

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 > High) enoughVacuum = 1;
if (InchesOfHg < Low) 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;

switch (ADMUX)
{
case 0x40:
InchesOfHg = -0.0376 * TenBitResult + 35.532;
Send_An_IntegerToMrLCD(15, 1, InchesOfHg, 4);
ADMUX = 0x41;
break;
case 0x41:
High = .034 * TenBitResult -.68;
Send_An_IntegerToMrLCD(4, 2, High, 3);
ADMUX = 0x42;
break;
case 0x42:
Low = .034 * TenBitResult -.68;
Send_An_IntegerToMrLCD(14, 2, Low, 3);
ADMUX = 0x40;
break;
default:
//Default code
break;
}

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.

Description:

Code (optional):