kohacraft Lab
/
kc_tv_hack
tv hack http://kohacraft.com/archives/1037090651.html
main.cpp@1:671aad1703f3, 2015-08-25 (annotated)
- Committer:
- kohacraft
- Date:
- Tue Aug 25 21:24:45 2015 +0000
- Revision:
- 1:671aad1703f3
- Parent:
- 0:d341bd9e7da7
vet1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kohacraft | 0:d341bd9e7da7 | 1 | #include "mbed.h" |
kohacraft | 0:d341bd9e7da7 | 2 | #include "MCP4922.h" |
kohacraft | 0:d341bd9e7da7 | 3 | DigitalOut myled(LED1); |
kohacraft | 0:d341bd9e7da7 | 4 | MCP4922 ad(0, dp9, dp4); //spiチャンネル1 /CS /LAT |
kohacraft | 0:d341bd9e7da7 | 5 | |
kohacraft | 0:d341bd9e7da7 | 6 | // x,y = -1〜+1 をADのフルレンジへ変換し出力する |
kohacraft | 0:d341bd9e7da7 | 7 | void outAd( float x , float y ) |
kohacraft | 0:d341bd9e7da7 | 8 | { |
kohacraft | 0:d341bd9e7da7 | 9 | int xtemp , ytemp; |
kohacraft | 0:d341bd9e7da7 | 10 | xtemp = (int)(2048.0 * x + 2047.0); |
kohacraft | 0:d341bd9e7da7 | 11 | if( xtemp < 0 ) |
kohacraft | 0:d341bd9e7da7 | 12 | xtemp = 0; |
kohacraft | 0:d341bd9e7da7 | 13 | if( xtemp > 4095 ) |
kohacraft | 0:d341bd9e7da7 | 14 | xtemp = 4095; |
kohacraft | 0:d341bd9e7da7 | 15 | |
kohacraft | 0:d341bd9e7da7 | 16 | ytemp = (int)(2048.0 * y + 2047.0); |
kohacraft | 0:d341bd9e7da7 | 17 | if( ytemp < 0 ) |
kohacraft | 0:d341bd9e7da7 | 18 | ytemp = 0; |
kohacraft | 0:d341bd9e7da7 | 19 | if( ytemp > 4095 ) |
kohacraft | 0:d341bd9e7da7 | 20 | ytemp = 4095; |
kohacraft | 0:d341bd9e7da7 | 21 | |
kohacraft | 0:d341bd9e7da7 | 22 | ad.select(0); |
kohacraft | 0:d341bd9e7da7 | 23 | ad.write( xtemp ); |
kohacraft | 0:d341bd9e7da7 | 24 | ad.select(1); |
kohacraft | 0:d341bd9e7da7 | 25 | ad.write( ytemp ); |
kohacraft | 0:d341bd9e7da7 | 26 | ad.update(); |
kohacraft | 0:d341bd9e7da7 | 27 | } |
kohacraft | 0:d341bd9e7da7 | 28 | |
kohacraft | 0:d341bd9e7da7 | 29 | int main() { |
kohacraft | 0:d341bd9e7da7 | 30 | |
kohacraft | 0:d341bd9e7da7 | 31 | ad.autoUpdate = 0; //しない |
kohacraft | 0:d341bd9e7da7 | 32 | ad.VrefA = 3300; //Vrefの電圧 |
kohacraft | 0:d341bd9e7da7 | 33 | ad.VrefB = 3300; //Vrefの電圧 |
kohacraft | 0:d341bd9e7da7 | 34 | ad.select(0); |
kohacraft | 0:d341bd9e7da7 | 35 | ad.buffered = 1; //Vrefのアンプ有効化 |
kohacraft | 0:d341bd9e7da7 | 36 | ad.setGain(1); //出力ゲインx1 |
kohacraft | 0:d341bd9e7da7 | 37 | ad.select(1); |
kohacraft | 0:d341bd9e7da7 | 38 | ad.buffered = 1; //Vrefのアンプ有効化 |
kohacraft | 0:d341bd9e7da7 | 39 | ad.setGain(1); //出力ゲインx1 |
kohacraft | 0:d341bd9e7da7 | 40 | |
kohacraft | 0:d341bd9e7da7 | 41 | float pi = 3.141592653589793238462; |
kohacraft | 0:d341bd9e7da7 | 42 | |
kohacraft | 0:d341bd9e7da7 | 43 | while(1) { |
kohacraft | 0:d341bd9e7da7 | 44 | |
kohacraft | 0:d341bd9e7da7 | 45 | for( float y=-1.0 ; y<=1 ; y+=1.0/60 ) |
kohacraft | 0:d341bd9e7da7 | 46 | |
kohacraft | 0:d341bd9e7da7 | 47 | for( float x=-1.0 ; x<=1 ; x+=1.0/60 ) |
kohacraft | 0:d341bd9e7da7 | 48 | { |
kohacraft | 0:d341bd9e7da7 | 49 | |
kohacraft | 0:d341bd9e7da7 | 50 | |
kohacraft | 0:d341bd9e7da7 | 51 | outAd( x, y ); |
kohacraft | 0:d341bd9e7da7 | 52 | } |
kohacraft | 0:d341bd9e7da7 | 53 | |
kohacraft | 0:d341bd9e7da7 | 54 | } |
kohacraft | 0:d341bd9e7da7 | 55 | } |