Where's The Code?

lightstring03

//   lightstring03
//   '03: renamed gradualfadefast to fadeslow
//        adding fadefast
//        adding fastblinker
//   OK 20DEC2014

byte MOC_logic = 3;  // alias output
int Intensity;      // conduction angle
int startPosition;  // delay time till start
int index = 0;
volatile boolean zeroCrossed = false;  // Flag
byte scenario = 0;    // which pattern
byte iteration = 0;   // iterations

void setup()
{
  pinMode(MOC_logic, OUTPUT);
  attachInterrupt(0,cueStart,RISING); // Ext_Int on D2
}

// ***** ***** ***** ***** //
void loop ()
{
  if (zeroCrossed == true)
  {
    enableOutput();
  }
}
// ***** ***** ***** ***** //

// ----- The Interrupt -----
void cueStart ()
{
  zeroCrossed = true;   //  !!!
}
// ---- ---- ---- ---- -----
// ---- ---- ---- ---- -----

void enableOutput ()
{
  // scenario 0 fadeslow
  // scenario 1 blinks
  // scenario 2 solid on
  if (scenario == 0)    // fadeslow
  {
    fadeslow();
    optohandler();
    index++;
    if (index > 367)
    {
      iteration ++;
      index = 0;
    }
    if (iteration == 5)
    {
      scenario = 1;    // the next scenario #
      iteration = 0;
    }
  }  
  
  else if (scenario == 1)  // blinks
  {
    blinker();
    optohandler();
    index++;
    if (index > 60)
    {
      iteration ++;
      index = 0;
    }
    if (iteration == 10)
    {
      scenario = 2;      // the next scenario #
      iteration = 0;     // reset
    }
  }
  
  else if (scenario == 2)  // fadefast
  {
    fadefast();
    optohandler();
    index++;
    if (index > 186)
    {
      iteration ++;
      index = 0;
    }
    if (iteration == 9)
    {
      scenario = 3;    // the next scenario #
      iteration = 0;
    }
  }  
  
  else if (scenario == 3)  // fastblinks
  {
    fastblinker();
    optohandler();
    index++;
    if (index > 30)
    {
      iteration ++;
      index = 0;
    }
    if (iteration == 10)
    {
      scenario = 0;      // the next scenario #
      iteration = 0;     // reset
    }
  }  
}

// ----------------------------

void blinker ()
{
  if (index < 30)                           // dot
  {Intensity = 7000;}
  else if ((index >= 30) && (index < 60))   //
  {Intensity = 0;}    
}

// ----------------------------
void fadeslow ()   // gradual fast ramp
{
  if (index < 6)
  {Intensity = 6000;}
  else if ((index >= 6) && (index <= 11))
  {Intensity = 5850;}    
  else if ((index >= 12) && (index <= 17))
  {Intensity = 5700;}  
  else if ((index >= 18) && (index <= 23))
  {Intensity = 5550;}
  else if ((index >= 24) && (index <= 29))
  {Intensity = 5400;}
  else if ((index >= 30) && (index <= 35))
  {Intensity = 5250;}  
  else if ((index >= 36) && (index <= 41))
  {Intensity = 5100;}
  else if ((index >= 42) && (index <= 47))
  {Intensity = 4950;}  
  else if ((index >= 48) && (index <= 53))
  {Intensity = 4800;}  
  else if ((index >= 54) && (index <= 59))
  {Intensity = 4650;}  
  else if ((index >= 60) && (index <= 65))
  {Intensity = 4500;}  
  else if ((index >= 66) && (index <= 71))
  {Intensity = 4350;}
  else if ((index >= 72) && (index <= 77))
  {Intensity = 4200;}  
  else if ((index >= 78) && (index <= 83))
  {Intensity = 4050;}  
  else if ((index >= 84) && (index <= 89))
  {Intensity = 3900;}    
  else if ((index >= 90) && (index <= 95))
  {Intensity = 3750;}  
  else if ((index >= 96) && (index <= 101))
  {Intensity = 3500;}  
  else if ((index >= 102) && (index <= 107))
  {Intensity = 3350;}    
  else if ((index >= 108) && (index <= 113))
  {Intensity = 3200;}  
  else if ((index >= 114) && (index <= 119))
  {Intensity = 3050;}  
  else if ((index >= 120) && (index <= 125))  //
  {Intensity = 2900;}    
  else if ((index >= 126) && (index <= 131))
  {Intensity = 2750;}  
  else if ((index >= 132) && (index <= 137))
  {Intensity = 2600;}  
  else if ((index >= 138) && (index <= 143))
  {Intensity = 2450;}  
  else if ((index >= 144) && (index <= 149))
  {Intensity = 2300;} 
  else if ((index >= 150) && (index <= 155))
  {Intensity = 2150;}  
  else if ((index >= 156) && (index <= 161))
  {Intensity = 2000;}  
  else if ((index >= 162) && (index <= 167))
  {Intensity = 1850;}   
  else if ((index >= 168) && (index <= 173))
  {Intensity = 1700;}  
  else if ((index >= 174) && (index <= 179))
  {Intensity = 1550;}    
  else if ((index >= 176) && (index <= 181))
  {Intensity = 1400;}
  else if ((index >= 182) && (index <= 187))
  {Intensity = 1250;}   //   ** midpt **
// ramp back down
  else if ((index >= 188) && (index <= 193))
  {Intensity = 1400;}
  else if ((index >= 194) && (index <= 199))
  {Intensity = 1550;}
  else if ((index >= 200) && (index <= 205))
  {Intensity = 1700;}
  else if ((index >= 206) && (index <= 211))
  {Intensity = 1850;}
  else if ((index >= 212) && (index <= 217))
  {Intensity = 2000;}
  else if ((index >= 218) && (index <= 223))
  {Intensity = 2150;}
  else if ((index >= 224) && (index <= 229))
  {Intensity = 2300;}
  else if ((index >= 230) && (index <= 235))
  {Intensity = 2450;}
  else if ((index >= 236) && (index <= 241))
  {Intensity = 2600;}
  else if ((index >= 242) && (index <= 247))
  {Intensity = 2750;}
  else if ((index >= 248) && (index <= 253))
  {Intensity = 2900;}
  else if ((index >= 254) && (index <= 259))
  {Intensity = 3050;}
  else if ((index >= 260) && (index <= 265))
  {Intensity = 3200;}
  else if ((index >= 266) && (index <= 271))
  {Intensity = 3350;}
  else if ((index >= 272) && (index <= 277))
  {Intensity = 3500;}
  else if ((index >= 278) && (index <= 283))
  {Intensity = 3750;}
  else if ((index >= 284) && (index <= 289))
  {Intensity = 3900;}
  else if ((index >= 290) && (index <= 295))
  {Intensity = 4050;}
  else if ((index >= 296) && (index <= 301))
  {Intensity = 4200;}
  else if ((index >= 302) && (index <= 307))
  {Intensity = 4350;}
  else if ((index >= 308) && (index <= 313))
  {Intensity = 4500;} 
  else if ((index >= 314) && (index <= 319))
  {Intensity = 4650;}
  else if ((index >= 320) && (index <= 325))
  {Intensity = 4800;}
  else if ((index >= 326) && (index <= 331))
  {Intensity = 4950;} 
  else if ((index >= 332) && (index <= 337))
  {Intensity = 5100;}
  else if ((index >= 338) && (index <= 343))
  {Intensity = 5250;}
  else if ((index >= 344) && (index <= 349))
  {Intensity = 5400;}
  else if ((index >= 350) && (index <= 355))
  {Intensity = 5550;}
  else if ((index >= 356) && (index <= 361))
  {Intensity = 5700;}
  else
  {Intensity = 5850;}  // index 362-367
}
  
// ----------------------------  
void optohandler ()
{
  if (Intensity == 0)  // OFF = (Intensity = 0)
  {
    delay (1);  // so same rise & dbl trig
  }
  else
  {
    startPosition = (8000 - Intensity); // "delay angle"
    delayMicroseconds (startPosition);
    digitalWrite(MOC_logic, HIGH);   
    delayMicroseconds (Intensity);  // "conduction angle"
    digitalWrite(MOC_logic, LOW);
  }
  zeroCrossed = false;  // Reset
}  

//-------------------------------
void fadefast ()   // gradual fast ramp
{
  if (index < 3)
  {Intensity = 6000;}
  else if ((index >= 4) && (index <= 6))
  {Intensity = 5850;}    
  else if ((index >= 7) && (index <= 9))
  {Intensity = 5700;}  
  else if ((index >= 10) && (index <= 12))
  {Intensity = 5550;}
  else if ((index >= 13) && (index <= 15))
  {Intensity = 5400;}
  else if ((index >= 16) && (index <= 18))
  {Intensity = 5250;}  
  else if ((index >= 19) && (index <= 21))
  {Intensity = 5100;}
  else if ((index >= 22) && (index <= 24))
  {Intensity = 4950;}  
  else if ((index >= 25) && (index <= 27))
  {Intensity = 4800;}  
  else if ((index >= 28) && (index <= 30))
  {Intensity = 4650;}  
  else if ((index >= 31) && (index <= 33))
  {Intensity = 4500;}  
  else if ((index >= 34) && (index <= 36))
  {Intensity = 4350;}
  else if ((index >= 37) && (index <= 39))
  {Intensity = 4200;}  
  else if ((index >= 40) && (index <= 42))
  {Intensity = 4050;}  
  else if ((index >= 43) && (index <= 45))
  {Intensity = 3900;}    
  else if ((index >= 46) && (index <= 48))
  {Intensity = 3750;}  
  else if ((index >= 49) && (index <= 51))
  {Intensity = 3500;}  
  else if ((index >= 52) && (index <= 54))
  {Intensity = 3350;}    
  else if ((index >= 55) && (index <= 57))
  {Intensity = 3200;}  
  else if ((index >= 58) && (index <= 60))
  {Intensity = 3050;}  
  else if ((index >= 61) && (index <= 63))  //
  {Intensity = 2900;}    
  else if ((index >= 64) && (index <= 66))
  {Intensity = 2750;}  
  else if ((index >= 67) && (index <= 69))
  {Intensity = 2600;}  
  else if ((index >= 70) && (index <= 72))
  {Intensity = 2450;}  
  else if ((index >= 73) && (index <= 75))
  {Intensity = 2300;} 
  else if ((index >= 76) && (index <= 78))
  {Intensity = 2150;}  
  else if ((index >= 79) && (index <= 81))
  {Intensity = 2000;}  
  else if ((index >= 82) && (index <= 84))
  {Intensity = 1850;}   
  else if ((index >= 85) && (index <= 87))
  {Intensity = 1700;}  
  else if ((index >= 88) && (index <= 90))
  {Intensity = 1550;}    
  else if ((index >= 91) && (index <= 93))
  {Intensity = 1400;}
  else if ((index >= 94) && (index <= 96))
  {Intensity = 1250;}   //   ** midpt **
// ramp back down
  else if ((index >= 97) && (index <= 99))
  {Intensity = 1400;}
  else if ((index >= 100) && (index <= 102))
  {Intensity = 1550;}
  else if ((index >= 103) && (index <= 105))
  {Intensity = 1700;}
  else if ((index >= 106) && (index <= 108))
  {Intensity = 1850;}
  else if ((index >= 109) && (index <= 111))
  {Intensity = 2000;}
  else if ((index >= 112) && (index <= 114))
  {Intensity = 2150;}
  else if ((index >= 115) && (index <= 117))
  {Intensity = 2300;}
  else if ((index >= 118) && (index <= 120))
  {Intensity = 2450;}
  else if ((index >= 121) && (index <= 123))
  {Intensity = 2600;}
  else if ((index >= 124) && (index <= 126))
  {Intensity = 2750;}
  else if ((index >= 127) && (index <= 129))
  {Intensity = 2900;}
  else if ((index >= 130) && (index <= 132))
  {Intensity = 3050;}
  else if ((index >= 133) && (index <= 135))
  {Intensity = 3200;}
  else if ((index >= 136) && (index <= 138))
  {Intensity = 3350;}
  else if ((index >= 139) && (index <= 141))
  {Intensity = 3500;}
  else if ((index >= 142) && (index <= 144))
  {Intensity = 3750;}
  else if ((index >= 145) && (index <= 147))
  {Intensity = 3900;}
  else if ((index >= 148) && (index <= 150))
  {Intensity = 4050;}
  else if ((index >= 151) && (index <= 153))
  {Intensity = 4200;}
  else if ((index >= 154) && (index <= 156))
  {Intensity = 4350;}
  else if ((index >= 157) && (index <= 159))
  {Intensity = 4500;} 
  else if ((index >= 160) && (index <= 162))
  {Intensity = 4650;}
  else if ((index >= 163) && (index <= 165))
  {Intensity = 4800;}
  else if ((index >= 166) && (index <= 168))
  {Intensity = 4950;} 
  else if ((index >= 169) && (index <= 171))
  {Intensity = 5100;}
  else if ((index >= 172) && (index <= 174))
  {Intensity = 5250;}
  else if ((index >= 175) && (index <= 177))
  {Intensity = 5400;}
  else if ((index >= 178) && (index <= 180))
  {Intensity = 5550;}
  else if ((index >= 181) && (index <= 183))
  {Intensity = 5700;}
  else
  {Intensity = 5850;}  // index 184-186
}

void fastblinker ()
{
  if (index < 15)                           // dot
  {Intensity = 7000;}
  else if ((index >= 15) && (index < 30))   //
  {Intensity = 0;}    
}


echopper_PBs_04

//  echopper_PBs_04
// 
//  External Interrupt on D2  !!
//
//  Commented out Display_It and its calls 062412
//  Levels = 7 ? ? ?

byte speed_idx = 0;      //
byte currentLevel = 0;   // comparison
byte newLevel = 0;       // comparison
byte Accel_Btn = 4;      // alias - Accelerate btn
byte Decel_Btn = 5;      // alias - Decelerate btn
byte Zeropwr = 6;        // alias - "kill" button
byte motorpin = 11;      // pin alias, PWM to gate/MOT
byte Level [6] = {0,20,40,100,175,250};
// Consider incl a Level between 40 and 100, which is a jump.
// byte Level [7] = {0,25,50,75,100,150,250};  ? ? ?
volatile boolean Detect = false;  // Interrupt Note


void setup()
{
  pinMode(motorpin, OUTPUT);
  pinMode(Zeropwr, INPUT);
  pinMode(Accel_Btn, INPUT);
  pinMode(Decel_Btn, INPUT);
  //Serial.begin(9600);
  attachInterrupt(0,Activity,RISING);  // Ext_Int on D2
}


void loop()
{
  if (Detect == true)
  {
    Decode();
  }
  if (currentLevel != newLevel)
  {
    analogWrite(motorpin,Level[speed_idx]);
    currentLevel = newLevel;
  }
}

void Activity()   // this is the Interrupt !
{
  Detect = true;
}

void Decode()
{
  Detect = false;          // clear out "Detect"
  if (digitalRead(Zeropwr) == HIGH)
  {
    speed_idx = 0;
    newLevel = 0;
    //Display_it();
  }
  else if (digitalRead(Accel_Btn) == HIGH)
  {
    Accelerate();
  }
  else if (digitalRead(Decel_Btn) == HIGH) // Activity detected wasn't Zeropwr or Accel_Btn
  {
    Decelerate();   // default = (A' & Z')
  }
}

void Accelerate()

  if (speed_idx < 5)
  {
    speed_idx ++;
  }
  newLevel = Level[speed_idx];
  //Display_it();
}

void Decelerate()
{
  if (speed_idx >= 1)
  {
    speed_idx --;
  }
  newLevel = Level[speed_idx];
  //Display_it();
}

No comments:

Post a Comment