Sudipto Trivedy
New member
I am using teensy 3.6 for the first time and I want to setup sample rate 250 Hz in teensy. Please help me with the sample code.
int sensorPin = A0;
int sensorValue = 0;
float voltage = 0.0;
char incomingByte;
String stringSend = ' ';
boolean STAT = false;
boolean STAT1 = false;
ADC adc;
void setup() {
Serial1.begin(9600);
analogReadResolution(12);
while (!Serial1) {
; // wait for serial port to connect. Needed for native USB port only
}
pinMode(sensorPin, INPUT);
}
void loop() {
if (Serial1.available() > 0) { // if the data came
incomingByte = Serial1.read();
Serial.println(incomingByte);
if(incomingByte == '0') {
STAT = true;
}
else if(incomingByte == '1'){
STAT = false;
stringSend = '#';
Serial1.print(stringSend);
delay(100);
}
else{
}
}
if(STAT)SendData();
}
void SendData(){
sensorValue = analogRead(sensorPin);
voltage = sensorValue * (5.0 / 4095.0);
//Serial.println(voltage);
stringSend = (String)voltage + ',';
Serial1.print(stringSend);
delay(100);
}
void SendLast(){
stringSend = '#';
Serial1.print(stringSend);
delay(100);
}
This is my code
int sensorPin = A0;
int sensorValue = 0;
float voltage = 0.0;
char incomingByte;
String stringSend = ' ';
boolean STAT = false;
boolean STAT1 = false;
ADC adc;
void setup() {
Serial1.begin(9600);
analogReadResolution(12);
while (!Serial1) {
; // wait for serial port to connect. Needed for native USB port only
}
pinMode(sensorPin, INPUT);
}
void loop() {
if (Serial1.available() > 0) { // if the data came
incomingByte = Serial1.read();
Serial.println(incomingByte);
if(incomingByte == '0') {
STAT = true;
}
else if(incomingByte == '1'){
STAT = false;
stringSend = '#';
Serial1.print(stringSend);
delay(100);
}
else{
}
}
if(STAT)SendData();
}
void SendData(){
sensorValue = analogRead(sensorPin);
voltage = sensorValue * (5.0 / 4095.0);
//Serial.println(voltage);
stringSend = (String)voltage + ',';
Serial1.print(stringSend);
delay(100);
}
void SendLast(){
stringSend = '#';
Serial1.print(stringSend);
delay(100);
}
This is my code