Tuesday, March 31, 2015

Spider 2 w Noise

/* 
 * File:   spider2main.c
 * Author: hmikelson
 *
 * Created on March 24, 2015, 4:30 PM
 */

#if defined(__XC)
    #include <xc.h>         /* XC8 General Include File */
#elif defined(HI_TECH_C)
    #include <htc.h>        /* HiTech General Include File */
#endif

#include <stdint.h>        /* For uint8_t definition */
#include <stdbool.h>       /* For true/false definition */
#include <stdlib.h>     /*rand()*/

#pragma config MCLRE=OFF,CP=OFF,WDTE=OFF,FOSC=INTOSCIO
#define _XTAL_FREQ 4000000
uint8_t sGPIO;

void init()
{
    //Configure GPIO Port
    ANSEL =  0b00000000;  //Configure all GPIO pins as digital
    TRISIO = 0b11001000;  //Set GP3 as input and the rest as outputs
                    // GP0 = eye 1, GP2 = eye 2, GP5 = speaker, GP4 = piezo
    OPTION_REGbits.nGPPU = 0;
    WPU = 0b00000100;     //Enable weak pullups on GP2
    //Configuer AD Convertor
    ADCON0 = 0x00;        //AD disabled
    ADRESH = 0x00;        //Init the AD Register
    //Configure Comparator
    CMCON0 = 0xFF;   // Comparator is turned off
    CMCON1 = 0x00;   // Comparator is turned off
    //Interrupt configuration
    INTCON = 0x00;   //Disable all interrupts
}

void vdelay(int n)
{
    int i;
    for (i=0;i<=n;i++)
    {
     __delay_us(1);
    }
}

void fade_eyes(int n) // PWM sweep high f to low f
{
 int i;
  {
   for (i=0;i<n;i++)
    {
     GPIO = 0b11000101;
     vdelay(i);
     GPIO = 0b11000000;
     vdelay(n-i);
    }
   for (i=0;i<n;i++)
    {
     GPIO = 0b11000101;
     vdelay(n-i);
     GPIO = 0b11000000;
     vdelay(i);
    }
  }
}

void scan_eyes(int n) // PWM sweep high f to low f
{
 int i,j,k;
 int i1,i2,i3,pw1,pw2;
 uint8_t sGPIO;

 i1=1; i2=-1; pw1=0; pw2=n;
 sGPIO = GPIO;
 for (k=0;k<6;k++)
 {
  for (j=0;j<n;j++)
   {
    for (i=0;i<n;i++)
     {
      if (i>pw1)
       {
        sGPIO = sGPIO & 0b11111110;
       }
      else
       {
        sGPIO = sGPIO | 0b00000001;
       }
      if (i>pw2)
       {
        sGPIO = sGPIO & 0b11111011;
       }
      else
       {
        sGPIO = sGPIO | 0b00000100;
       }
      GPIO = sGPIO;
     }
    pw1 = pw1 + i1;
    pw2 = pw2 + i2;
   }
  i3 = i1; i1 = i2, i2 = i3;
 }
}

void dark_eyes(void) // PWM sweep high f to low f
{
 GPIO = 0b11000000;
 __delay_ms(2000);
}

void scream(int n) // PWM sweep high f to low f
{
 int i,r,j;
  {
    for (j=0;j<n;j++)
    {
     for (i=0;i<j;i++)
      {
       r=rand()%8;
       GPIO = 0b11100101;
       vdelay(i+r);
       GPIO = 0b11000000;
       vdelay(n-i+r);
       i = i+r;
      }
    }
  }
}

void scream2(int n) // PWM sweep high f to low f
{
 int i,r,j;
  {
    for (j=0;j<n;j++)
    {
     for (i=0;i<j;i++)
      {
       r=rand()%8;
       GPIO = 0b11010101;
       vdelay(i+r);
       GPIO = 0b11000000;
       vdelay(n-i+r);
       i = i+r;
      }
    }
  }
}

void scream3(int n) // PWM sweep high f to low f
{
 int i,j,k,r;
 int i1,i2,i3,pw1,pw2;
 uint8_t sGPIO;

 i1=1; i2=-1; pw1=0; pw2=n;
 sGPIO = GPIO;
 for (k=0;k<2;k++)
 {
  for (j=0;j<n;j++)
   {
    for (i=0;i<n;i++)
     {
      if (i>pw1)
       {
        sGPIO = sGPIO & 0b11011110;
       }
      else
       {
        sGPIO = sGPIO | 0b00100001;
       }
      if (i>pw2)
       {
        sGPIO = sGPIO & 0b11101011;
       }
      else
       {
        sGPIO = sGPIO | 0b00010100;
       }
      GPIO = sGPIO;
      r=rand()%6;
      vdelay(r);
     }
    pw1 = pw1 + i1;
    pw2 = pw2 + i2;
   }
  i3 = i1; i1 = i2, i2 = i3;
 }
}

void main()
{
uint8_t r,r2;

 init();

 while(1)
  {
   r=rand()%32;
   //r=4;
   r2 = rand()%8+1;
   switch (r)
    {
     case 1:
     fade_eyes(100*r2);
     break;

     case 2:
     fade_eyes(20*r2);
     break;

     case 3:
     scan_eyes(20*r2);
     break;

     case 4:
     scream(16*r2);
     break;

     case 5:
     scream2(8*r2);
     break;

     case 6:
     scream3(8*r2);
     break;

     default:
     dark_eyes();
    }
  }
}

Wednesday, March 11, 2015

UV LED Exposure System


This is the layout for an exposure system based on UV LEDs.  Be sure to use the wider angle LEDs (30 degrees).  I offset a piece of glass about 1-2 inches from the surface when exposing.  I am also using a frosted shower glass over the LEDs.  You can delete some of these for a smaller system.  This one uses 180 LEDs.  There are about 3V per LED so you need at least 18V to make this work.  Adjust the resistors so that you have the correct current per LED (~30 mA).  A 1 amp supply should work for this.  I mounted mine in a picture box from Michael's.