Sunday, July 31, 2011

Arduino Uno Buzzer: My First Program

int timer = 100;           
int iterator = 1;
int olditerator=1;
int bifurcate = 0;
int limit = 1000;
double period;
double wait;

void setup() {
  for (int thisPin = 1; thisPin < 13; thisPin++)  {
    pinMode(thisPin, OUTPUT);      
  }
}

void loop() {

  for (int thisPin = 13; thisPin >= 1; thisPin--) { 
    // digitalWrite(thisPin, HIGH);
    if (thisPin == 13 || thisPin == 5 || thisPin == 1 || thisPin == 8) { 
          olditerator=iterator;
          while (olditerator>1) {
          analogWrite(thisPin, olditerator);
          olditerator--;
          }
        while (iterator < limit) {
          period = ((iterator * 4.86510264) + iterator);  
          wait = period / 2; 
          if (iterator < bifurcate) {
             if (iterator % 2 ==0) {analogWrite(thisPin, iterator*200);}
             else {analogWrite(thisPin, iterator*200); delay(10);}
             delayMicroseconds(wait);
                             } 
           if (iterator > bifurcate) {  
          delayMicroseconds(wait);   
          digitalWrite(thisPin, LOW);  
          delayMicroseconds(wait);   
          analogWrite(thisPin, iterator+500);
          analogWrite(thisPin, iterator);
          olditerator=iterator;
          while (olditerator>1) {
          analogWrite(thisPin, olditerator);
          analogWrite(thisPin, iterator);
          olditerator--;
          }
          delayMicroseconds(wait); 
          digitalWrite(thisPin, LOW);
    
                             } 
                                               
          iterator++;  
                        }
          iterator=0;                      
                     }
    delay(timer);
    digitalWrite(thisPin, LOW);
  }
}

Friday, July 1, 2011

Pad and sort list of IP numbers

L = ['123.76.9.2', '125.76.9.3', '123.76.10.12', '92.93.3.79', '92.93.3.78', '222.222.222.222', '222.222.1.222']
L = sorted([".".join(['%03d' % int(j) for j in i.split('.')]) for i in L])
print L