-
Notifications
You must be signed in to change notification settings - Fork 588
/
Program.cs
49 lines (41 loc) · 1.48 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Threading;
using Iot.Device.Adc;
using force_sensitive_resistor;
Console.WriteLine("Hello Fsr408 capacitor Sample!");
// Use this sample when using ADC for reading
StartReadingWithADC();
// Use this sample if using capacitor for reading
// StartReadingWithCapacitor();
void StartReadingWithADC()
{
FsrWithAdcSample fsrWithAdc = new();
while (true)
{
int value = fsrWithAdc.Read(0);
double voltage = fsrWithAdc.CalculateVoltage(value);
double resistance = fsrWithAdc.CalculateFsrResistance(voltage);
double force = fsrWithAdc.CalculateForce(resistance);
Console.WriteLine($"Read value: {value}, milli voltage: {voltage.ToString("f2")}, resistance: {resistance.ToString("f2")}, approximate force in Newtons: {force.ToString("f2")}");
Thread.Sleep(500);
}
}
void StartReadingWithCapacitor()
{
FsrWithCapacitorSample fsrWithCapacitor = new();
while (true)
{
int value = fsrWithCapacitor.ReadCapacitorChargingDuration();
if (value == 30000)
{ // 30000 is count limit, if we got this count it means Fsr has its highest resistance, so it is not pressed
Console.WriteLine("Not pressed");
}
else
{
Console.WriteLine($"Pressed {value}");
}
Thread.Sleep(500);
}
}