tailieunhanh - Practical Arduino Cool Projects for Open Source Hardware- P23
Practical Arduino Cool Projects for Open Source Hardware- P23: A schematic or circuit diagram is a diagram that describes the interconnections in an electrical or electronic device. In the projects presented in Practical Arduino, we’ve taken the approach of providing both a photograph and/or line drawing of the completed device along with a schematic. While learning to read schematics takes a modest investment of your time, it will prove useful time and time again as you develop your projects. With that in mind, we present a quick how-to in this section | CHAPTER 11 OSCILLOSCOPE LOGIC ANALYZER To send a set of eight 10-bit values plus seven separator characters and a newline CRLF at the end requires between 17 and 41 bytes of data to be transmitted via the USB connection depending on the specific values. This limits it to sending to around 350 samples second on average with the serial connection set to 115200bps. Later examples attempt to overcome some of these limitations. First the program defines the cbi and sbi macros so we can use them to change the prescaler values. ifndef cbi define cbi sfr bit _SFR_BYTE sfr _BV bit endif ifndef sbi define sbi sfr bit _SFR_BYTE sfr _BV bit endif Then the program defines a variable that will be used to store each reading as it is taken. int val The setup function sets the prescaler to 16 as described previously then sets digital pins 6 and 7 to input mode and opens the connection to the host at 115200bps. void setup sbi ADCSRA ADPS2 cbi ADCSRA ADPS1 cbi ADCSRA ADPSo pinMode 6 INPUT pinMode 7 INPUT 115200 The program loops as fast as possible starting by taking a reading from each analog input starting at input 0 and counting up to analog input 5. The value from each input is sent straight to the host as soon as it is read with a space character to separate them. void loop for int i 0 i 6 i analogRead i Because probes 6 and 7 are connected to digital inputs we have to fudge the values. If the reading is low we return a value of 0 if it s high we return a value of 1023. That way high and low values show the same range as the analog inputs even though they ll never show an intermediate value like an analog input. Note that the values returned for input 6 have a space appended as a separator for the next value. if digitalRead 6 1 1023 else 0 199 CHAPTER 11 OSCILLOSCOPE LOGIC ANALYZER if digitalRead 7 1 1023 else o Once all the samples have been sent to the host the
đang nạp các trang xem trước