チーム1924
課題名
ふかふかタマゴ
研究者名
Takuma Suzuki
Kohei Takubo
概要
温度センサーを用いて、温度によってタマゴが割れ、孵化させる。
フィードバックとしてLCDに得たデータの値を16進数表示させる。
使用した機器
・PSoC基盤 1台
・温度センサー(LM35)1つ
・ジャンパー 4本
・MiniProg 1本
・通信用ケーブル 1本
仕様
PSoC側のコード
#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
void main(void)
{
unsigned int adc_data; char* strPtr; PGA_Start(PGA_HIGHPOWER); LCD_Start(); LCD_InitBG(LCD_SOLID_BG); M8C_EnableGInt; ADCINC_Start(ADCINC_HIGHPOWER); ADCINC_GetSamples(0); UART_CmdReset(); UART_IntCntl(UART_ENABLE_RX_INT); Counter8_WritePeriod(155); Counter8_WriteCompareValue(77); Counter8_Start();
UART_Start(UART_PARITY_NONE); M8C_EnableGInt; UART_CPutString("\r\nWelcome to PSoC UART test program.V1.1\r\n"); while(1){ while(ADCINC_fIsDataAvailable() == 0); adc_data = ADCINC_wClearFlagGetData(); LCD_Position(0,0); LCD_PrHexInt(adc_data); LCD_DrawBG(1,0,16,(adc_data/5));
if(adc_data > 0b101011100) break; else if(adc_data > 0b101011000){ UART_PutChar('E'); } else if(adc_data > 0b101010011){ UART_PutChar('D'); } else if(adc_data > 0b101001000){ UART_PutChar('C'); } else if(adc_data > 0b101000000){ UART_PutChar('B'); } else{ UART_PutChar('A'); } }
}
Processing側のコード
import processing.serial.*;
Serial Port;
PImage imge1,imge2,imge3,imge4,imgb;
int drawflag;
void setup(){
size(1200,1200);
background(255,255,255);
imge1 = loadImage("imge1.png");
imge2 = loadImage("imge2.png");
imge3 = loadImage("imge3.png");
imge4 = loadImage("imge4.png");
imgb = loadImage("imgb.png");
Port = new Serial(this,"COM4",38400);
}
void serialEvent(Serial p){
char flag = Port.readChar(); if(flag=='A') drawflag=1; else if(flag=='B') drawflag=2; else if(flag=='C') drawflag=3; else if(flag=='D') drawflag=4; else if(flag=='E') drawflag=5;
}
void draw() {
background(255,255,255);
if(drawflag==1)
image(imge1, 200, 200, width*2/3, height*2/3);
else if(drawflag==2)
image(imge2, 200, 200, width*2/3, height*2/3);
else if(drawflag==3)
image(imge3, 200, 200, width*2/3, height*2/3); else if(drawflag==4) image(imge4, 200, 200, width*2/3, height*2/3);
else if(drawflag==5) image(imgb, 50, 50, width*8/9, height*8/9);
}
実行画面
考察
チーム1726とチーム1466とラボlab3_adcを参考に作成した。
今回は温度センサーから出力される電圧をアナログデジタル変換し、その値をPSoCで処理後PCソフトウェアに送る。
PCソフトウェア側では受け取った値をもとに画像表示を実現した。
改善点として、温度センサーのブレにより画像が乱れてしまうことを解決する。
方法としては、よい温度センサーを用いることなどが考えられる。
- 最終更新:2019-06-18 16:47:57