Week11 - Input devices

CB1633FC62F02C6ECDFB5693D961C7D1

Design the Reflect

Create the OP580 Device

Draw the symbol of OP580

Draw the Package of OP580

Create the Device of OP580

Draw the schematic

Draw the PCB board

Output the image of traces

traces

Output the image of interior

interio

Arduino and Reflect with ATtiny45

Reference: [Programming an Atiny w/Arduino 1.6(or 1.0)] (http://highlowtech.org/?p=1695)

Arduino ATtiny45 Pin

Arduino ATiny45 Setting

1
const int analogInPin =  A2;  // Analog input pin that the potentiometer is attached to
int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

void setup() {
  pinMode(3, OUTPUT);
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  if(outputValue > 240){
    digitalWrite(3, LOW);
  }else{
    digitalWrite(3, HIGH);
  }
  delay(10);
}

CB1633FC62F02C6ECDFB5693D961C7D1

Add Serial Port

Reference: ATtiny85 & ATtiny84 Analog Pins, Serial Communication, etc.

1
#include "SoftwareSerial.h"

const int analogInPin =  A2;  // Analog input pin that the potentiometer is attached to
int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

const int Rx = 1; // this is physical pin 7
const int Tx = 2; // this is physical pin 6
SoftwareSerial mySerial(Rx, Tx);

void setup() {
  pinMode(3, OUTPUT);
  pinMode(Rx, INPUT);
  pinMode(Tx, OUTPUT);
  mySerial.begin(115200); // send serial data at 9600 bits/sec
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  mySerial.print("sensorValue = ");
  mySerial.println(outputValue);


  if(outputValue > 240){
    digitalWrite(3, LOW);
  }else {
    digitalWrite(3, HIGH);
  }
  delay(10);
}

Test Results:

outputValue: 210~240

outputValue: 160~180

outputValue > 240

Fix the Bug when the outputValue < 180

1
#include "SoftwareSerial.h"

const int analogInPin =  A2;  // Analog input pin that the potentiometer is attached to
int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

const int Rx = 1; // this is physical pin 7
const int Tx = 2; // this is physical pin 6
SoftwareSerial mySerial(Rx, Tx);

void setup() {
  pinMode(3, OUTPUT);
  pinMode(Rx, INPUT);
  pinMode(Tx, OUTPUT);
  mySerial.begin(115200); // send serial data at 9600 bits/sec
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  mySerial.print("sensorValue = ");
  mySerial.println(outputValue);


  if(outputValue > 240 || outputValue < 180){
    digitalWrite(3, LOW);
  }else{
    digitalWrite(3, HIGH);
  }
  delay(10);
}

File Download

Eagle


This work is licensed under a Creative Commons Attribution 4.0 International License.

文章目录
  1. 1. Design the Reflect
    1. 1.1. Create the OP580 Device
      1. 1.1.1. Draw the symbol of OP580
      2. 1.1.2. Draw the Package of OP580
      3. 1.1.3. Create the Device of OP580
    2. 1.2. Draw the schematic
    3. 1.3. Draw the PCB board
    4. 1.4. Output the image of traces
    5. 1.5. Output the image of interior
  2. 2. Arduino and Reflect with ATtiny45
    1. 2.1. Arduino ATtiny45 Pin
    2. 2.2. Arduino ATiny45 Setting
    3. 2.3. Reflect and Blink with Arduino
    4. 2.4. Add Serial Port
      1. 2.4.1. Test Results:
    5. 2.5. Fix the Bug when the outputValue < 180
    6. 2.6. File Download
,