tv hack http://kohacraft.com/archives/1037090651.html

Dependencies:   MCP4922 mbed

main.cpp

Committer:
kohacraft
Date:
2015-08-25
Revision:
1:671aad1703f3
Parent:
0:d341bd9e7da7

File content as of revision 1:671aad1703f3:

#include "mbed.h"
#include "MCP4922.h"
DigitalOut myled(LED1);
MCP4922 ad(0, dp9, dp4);    //spiチャンネル1 /CS /LAT

// x,y = -1〜+1 をADのフルレンジへ変換し出力する
void outAd( float x , float y )
{
    int xtemp , ytemp;
    xtemp = (int)(2048.0 * x + 2047.0);
    if( xtemp < 0 )
        xtemp = 0;
    if( xtemp > 4095 )
        xtemp = 4095;

    ytemp = (int)(2048.0 * y + 2047.0);
    if( ytemp < 0 )
        ytemp = 0;
    if( ytemp > 4095 )
        ytemp = 4095;
    
    ad.select(0);
    ad.write( xtemp ); 
    ad.select(1);
    ad.write( ytemp ); 
    ad.update();
}

int main() {
    
    ad.autoUpdate = 0; //しない
    ad.VrefA = 3300; //Vrefの電圧
    ad.VrefB = 3300; //Vrefの電圧
    ad.select(0);
    ad.buffered = 1; //Vrefのアンプ有効化
    ad.setGain(1);  //出力ゲインx1
    ad.select(1);
    ad.buffered = 1; //Vrefのアンプ有効化
    ad.setGain(1);  //出力ゲインx1
    
    float pi = 3.141592653589793238462;
    
    while(1) {
        
        for( float y=-1.0 ; y<=1 ; y+=1.0/60 )
        
        for( float x=-1.0 ; x<=1 ; x+=1.0/60 )
        {
        
        
            outAd(  x, y );
        }
        
    }
}