HOW TO MAKE -PWM+SENSOR+MAP CODE IN Ardinu

Thread Starter

SUN SHINE

Joined Jan 6, 2017
13
Hi

i am trying to make a code for Ardinu that use the map function with PWM and the values comes from sensor
could you help me
i have already codes for using PWM with LED but i want to connect the Ardinu with sensor beside of the led and map the values from the sensor
i tried to explain .if something is not clear ask me please

here is example




int green = 11; // Digital pin 11 - Green LED
int blue = 9; // Digital pin 9 - Blue LED
int time = 5; // define delay element
int pulsewidth; // define pulsewidth (0-255)

void setup() {
//
}

void loop() {
// slowly fade the LEDs to full brightness
for (pulsewidth=0; pulsewidth = 0; pulsewidth--){
analogWrite(green, pulsewidth);
analogWrite(red, pulsewidth);
analogWrite(blue, pulsewidth);
delay(time);
}
}
 

Thread Starter

SUN SHINE

Joined Jan 6, 2017
13
i mean the values that comes from the sensors will first enter to the map function which will convert the
range that take from the sensor to the range of the pwm and after that controlling the lighting of the led by pwm
 

djsfantasi

Joined Apr 11, 2010
9,156
Have you read up on the map function? To me, what you are asking is very simple.

I don't know what you are using as a sensor nor what it returns to the Arduino.

PWM takes a value for duty cycle in the range of 0 to 255. Hence, the map function would have a toLow value of 0 and a toHigh value of 255.

The map function would have values for fromLow and fromHigh corresponding to the range of values returned by your sensor.

I wonder if your sensor returns s value between 0 and 255, why you need to use map at all.

If you don't want the full range of the sensor or PWM, you would adjust the end points in the map function.
 
Top