Comments (1)
#define cbi(addr, bit) addr &= ~(1 << bit) // addrのbit目を'0'にする
#define sbi(addr, bit) addr |= (1 << bit) // addrのbit目を'1'にする
#define _PULSE_PIN 2
// シリアル通信について TinkerCad と実物で相違がある。
// Linux の改行が <LF><CR> だかで、文字+Enter という送信になってるのかも
// まあ Windows 使わないからいいや
const char PULSE_PIN = 2;
const char ANALOG_READ_PIN = A5;
void setup()
{
Serial.begin(9600);
Serial.setTimeout(2^32-1); //no timeout
pinMode( PULSE_PIN , OUTPUT);
digitalWrite(PULSE_PIN, LOW);
// PIC と違い レジスタ名bits.ビット名での操作はできない。
// & は 1&1=1, 1&0=0, 0&1=0, 0&0=0
// まず上位 5ビットを保持したまま、下位3ビットをクリア
ADCSRA = ADCSRA & 0b11111000;
// 第2 ビットを 1 に変える。
// | or は 1&1=1, 1&0=1, 0&1=1, 0&0=0 だから、第2 ビット以外は元の値が保持される
ADCSRA = ADCSRA | 0b00000010;
discharge(1000);
}
void discharge(unsigned int td) {
digitalWrite(PULSE_PIN, LOW);
delay(td);
}
unsigned long charge() {
// digitalWrite(PULSE_PIN, HIGH);
sbi(PORTD, PORTD2);
return micros();
}
void loop() {
double _R;
_R=r_setup();
// TinkerCad では文字を送る必要があったが、実物では Enter で反応する
Serial.println("Enter to reset registor");
// TinkerCad では不要だったけど、これがないと Serial.available()>0 になってしまう。
Serial.end();
Serial.begin(9600);
while(Serial.available()==0){
unsigned long time_start = charge();
while ( analogRead(ANALOG_READ_PIN) < 647){};//1023*64.2=646.5。
double T = micros() - time_start; // T: 時定数
double c=T/_R; // [uF]
unsigned int td=-_R*c*log(1.0/500.0)/1.0e3;
td = (td>1000)*td + (td<=1000)*1000;
Serial.println(td);
discharge(td);
Serial.println(c,16);
digitalWrite(PULSE_PIN, LOW);
}
Serial.end();
Serial.begin(9600);
}
double r_setup()
{
double registor;
double x; // general purpose
short i; //
char a; // general purpose
Serial.println("Input the registor [Ohm]");
Serial.println("Scientific notation only (ex, 1.23e-4)");
while (Serial.available() == 0) {};
x=Serial.parseFloat();
a=Serial.read();
i=Serial.parseInt();
registor=x*pow(10.0,i);
Serial.print("Registor: ");
Serial.print(registor,16);
Serial.println(" Ohm");
return registor;
}
待ち時間が長いから付け替える方が便利かな。
from arduinodeasobu.
Related Issues (20)
- usb 切り替え IC を使う切り替え機
- 書き込み失敗 HOT 1
- usbasp HOT 1
- minicore で arduinoisp.ino が動かないんだが HOT 3
- GL850G #3
- sun ace 80 の 5000rpm のやつ
- 書き込み失敗調査 HOT 7
- a-p-prog の wait って HOT 1
- 3.3V LDO
- リレーが単純 HOT 2
- TC7USB40FT の USB switcher 、レギュレータの配線 3.3V と GND 逆になっている (設計図)
- NiMHチャージャー
- vcc の値を読む
- BME280
- 温度センサー MCP9700 は誤差が ±4℃と大きすぎる。
- usb スイッチ用フォトリレー HOT 1
- 秋月 会社一覧
- USB type-c ケーブルメモ
- usb hub 2.1
- usb hub 2.1 の電源選択
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduinodeasobu.