Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:26508adf6f76
- Child:
- 1:3e1c05f8d7e8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Fri Oct 09 09:07:35 2020 +0000
@@ -0,0 +1,136 @@
+/**************************
+2020/10/09
+編集者:福田哲生
+
+回路が新しくなり、AnalogOutから電圧が出力できるようになった。これを受けて出力場所の変更を行う。
+これに伴いプログラムを一新することにした。
+p18に0~1の出力を行うとそれが0~570Vとして出力できる。
+p14~p17で電圧、周波数を10V/Hzずつ変更するようにした。
+電圧周波数の初期値は570V/100Hz
+
+2ボタン同時押しでリセットされるようにしたがうまく動作しなかったためその部分は変更が必要。
+
+***************************/
+#include "mbed.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+AnalogOut signal(p18);//AnalogOutピン(1768は18番ピン)
+Timer timer;//カウンタ
+Timer chtimer;//チャタリング用タイマー
+int Freq = 100;//正弦波の周波数
+int Volt = 570;//印加電圧値
+
+//スイッチ用ピンの宣言
+DigitalIn VoltUp(p14);
+DigitalIn VoltDown(p15);
+DigitalIn FreqUp(p16);
+DigitalIn FreqDown(p17);
+
+int swflag = 0;//スイッチ用フラグ
+
+#define MIN_TIME_DIFF 200//チャタリング用待機時間
+
+//LEDの宣言
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+
+int main() {
+ double t=0.0;
+ int timediff = 0;
+ timer.start();
+ chtimer.start();
+ while(1) {
+ if(VoltUp.read() == 1){//黄押すと電圧10V増加
+ timediff = chtimer.read_ms();
+ if(timediff > MIN_TIME_DIFF) {
+ Volt = Volt + 10;
+ if(Volt > 570){
+ Volt = 570;
+ }
+ }
+ chtimer.reset();
+ led1 = 1;
+ led2 = 0;
+ led3 = 0;
+ led4 = 0;
+ wait(0.5);
+ }
+ if(VoltDown.read() == 1){//青押すと周波数10Hz減少
+ timediff = chtimer.read_ms();
+ if(timediff > MIN_TIME_DIFF) {
+ Volt = Volt - 10;
+ if(Volt < 0){
+ Volt = 0;
+ }
+ }
+ chtimer.reset();
+ led1 = 0;
+ led2 = 1;
+ led3 = 0;
+ led4 = 0;
+ wait(0.5);
+ }
+ if(FreqUp.read() == 1){//白押すと周波数10Hz増加
+ timediff = chtimer.read_ms();
+ if(timediff > MIN_TIME_DIFF) {
+ Freq = Freq + 10;
+ }
+ chtimer.reset();
+ led1 = 0;
+ led2 = 0;
+ led3 = 1;
+ led4 = 0;
+ wait(0.5);
+ }
+ if(FreqDown.read() == 1){//黒押すと周波数10Hz減少
+ timediff = chtimer.read_ms();
+ if(timediff > MIN_TIME_DIFF) {
+ Freq = Freq - 10;
+ if(Freq < 0){
+ Freq = 0;
+ }
+ }
+ chtimer.reset();
+ led1 = 0;
+ led2 = 0;
+ led3 = 0;
+ led4 = 1;
+ wait(0.5);
+ }
+ if(VoltUp.read() == 1 && VoltDown.read() == 1){//黄,青同時押しで電圧を570Vにリセット
+ timediff = chtimer.read_ms();
+ if(timediff > MIN_TIME_DIFF) {
+ Volt = 570;
+ }
+ chtimer.reset();
+ led1 = 1;
+ led2 = 1;
+ led3 = 0;
+ led4 = 0;
+ wait(0.5);
+ }
+ if(FreqUp.read() == 1 && FreqDown.read() == 1){//白,黒同時押しで周波数を100Hzにリセット
+ timediff = chtimer.read_ms();
+ if(timediff > MIN_TIME_DIFF) {
+ Freq = 100;
+ }
+ chtimer.reset();
+ led1 = 0;
+ led2 = 0;
+ led3 = 1;
+ led4 = 1;
+ wait(0.5);
+ }
+ //sin波の出力※0~1の値をp18に送るため570で割る
+ t = (double)timer.read_us() * 0.000001;
+ signal = ((0.5 + sin(2.0 * 3.1415926 * Freq * t)/2) * Volt) / 570;
+ led1 = 1;
+ led2 = 1;
+ led3 = 1;
+ led4 = 1;
+ }
+}