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

Dependencies:   MCP4922 mbed

Revision:
0:d341bd9e7da7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Aug 25 21:21:29 2015 +0000
@@ -0,0 +1,55 @@
+#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 );
+        }
+        
+    }
+}