Hi,
For school, we have a project to make a FAKE bomb. With the potentiometer, we need to set the time. The min value is 10 and max 240. Now I've read some forums and everyone says you have to use the map() function. When I code it, it gives an error.
I am using an Arduino Uno ATmega328P/PA with a Multi-function shield on top.
I'm coding in C.
Can someone help?
This is my code
#include <avr/io.h>
#include <usart.h>
#include <string.h>
#include <display.h>
#include <util/delay.h>
void initADC(){
ADMUX |= (1<<REFS0);
ADCSRA |= (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
ADCSRA |= (1<<ADEN);//Enable de ADC
}
void loop(){
initUSART();
initADC();
initDisplay();
int pMin = 10;
int pMax = 240;
while (1) {
ADCSRA |= (1<<ADSC);
loop_until_bit_is_clear(ADCSRA,ADSC);
uint16_t value = ADC;
value = map(value,pMin,pMax,0,100);
printf("Value:%d\n", value);
writeNumber(value);
}
return 0;
}
Would it not make sense to tell us what the error is? Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.
Read the how to use this forum-please read sticky to see how to properly post code and some advice on how to ask an effective question. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.
Where did you get that code?
groundFungus:
Would it not make sense to tell us what the error is? Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.
Read the how to use this forum-please read sticky to see how to properly post code and some advice on how to ask an effective question. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.
Where did you get that code?
In function `main':
<artificial>:(.text.startup+0x96): undefined reference to `map'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\ATmega328P\firmware.elf] Error 1
Now I've changed some things. When you turn the potentiometer the value reduces or increases. When you press on Button 2 the timer goes off.
Some code is from my teacher. I am just a beginner and don't really understand this.
I fixed my problem. Just needed to use a formula that the potentiometer only shows values between 10 and 240. This is without using the map function
void initADC(){
ADMUX |= (1<<REFS0);
ADCSRA |= (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
ADCSRA |= (1<<ADEN);//Enable de ADC
}
int main(){
initUSART();
initADC();
while (1){
ADCSRA |= (1<<ADSC);
loop_until_bit_is_clear(ADCSRA,ADSC);
uint16_t value = ADC* 0.225 + 10;
writeNumberAndWait(value,20);
}
}