Reversing value.

Hi guys, i try to make AC dimmer, for now work perfect but reading sensor values is exactly opposite of my needs,when voltage on sensor pin increases, lamp glow decrease. I want when voltage on sensor pin increase light increase too. Here is my code, may be answer is some where in map functions, any suggestions?

[
#define triacPulse 5

int val;

void setup()  {
   pinMode(2, INPUT);
   digitalWrite(2, HIGH); // pull up
   pinMode(triacPulse, OUTPUT);

  }

void loop() {
 
    attachInterrupt(0, acon, FALLING); 
   
void acon()  
   {
    delayMicroseconds((analogRead(0) * 6) + 1000); 
    digitalWrite(triacPulse, HIGH);
    delayMicroseconds(200);  
   
    digitalWrite(triacPulse, LOW);
   }

Change this line:

    delayMicroseconds((analogRead(0) * 6) + 1000);

into:

    delayMicroseconds(7138 - (analogRead(0) * 6));

This makes the phase cutting shorter as the voltage increases.

... and something that you did not ask about:

Calling attachInterrupt(...) in a loop is probably not what you want to do.

pylon:
Change this line:

    delayMicroseconds((analogRead(0) * 6) + 1000);

into:

    delayMicroseconds(7138 - (analogRead(0) * 6));

This makes the phase cutting shorter as the voltage increases.

Thanks this is work fantastic!