I have a high power LED driver board, this board used as a driver board for a 60 W LED,…
- User
I have a high power LED driver board, this board used as a driver board for a 60 W LED, in this board there is a 10 K ohm potentiometer, I measured the minimum and maximum values of this potentiometer in board for minimum value it was 65 and in maximum is 337; I want to use this values to light up 6 LEDs (white color) and act like a LED bar graph and based on value of potentiometer light on or off leds, I did a work to directly using a at mega 32A to control this process but after for led 6 and there are some problems, so instead of directly connecting the leds to at mega I'm working on using 2n2222 transistors, for this purpose what I need to do and please calculate the resistor I needed
- Assistant
- User
I have this code, but unfortunately it dose not work what could be problem #define F_CPU 16000000UL // Clock frequency of 16 MHz #include <avr/io.h> #include <util/delay.h>
#define NUM_LEDS 6 #define ADC_MIN 65 #define ADC_MAX 337
// Initialize ADC void ADC_Init(){ // AVCC with external capacitor at AREF pin ADMUX = (1<<REFS0); // Enable ADC and prescaler of 64 (for 16MHz clock) ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1); }
// Read ADC value uint16_t ADC_Read(uint8_t channel){ // Select ADC channel with safety mask ADMUX = (ADMUX & 0xF8)|channel; // Single Conversion mode ADCSRA |= (1<<ADSC); // Wait until ADC conversion is complete while( ADCSRA & (1<<ADSC) ); return ADC; }
// Maps a number from one range to another range int map(int x, int in_min, int in_max, int out_min, int out_max){ return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; }
- Assistant
Your code looks generally fine for reading an ADC value and then deciding how many LEDs to light up based on that value. There are a few potential issues that could be causing your code not to work as expected:
- User
ok give me the code for this work
- Assistant