class: center, middle # Hardware Eslam Adel email: `eslam.a.mahmoud@eng1.cu.edu.eg` --- class: top, left ## Circuits and Electronics Electric circuit is a closed path that current flow through it. It contains different electrical components * Resistor / Potentiometer (Variable resistor) Ohm or kilOhm   --- ## Capacitors Unit is Farad or micro Farad  ---  --- ## Inductor or Transformers Henry (H)   --- ## Switches Break or connect circuit  --- ## semiconductor (Electronics) * Diodes Current move in one direction and prevented in the other direction     ---  --- ## Light emitting diode (Led )  --- ## Photo-diode  --- ## Transistors 3 Terminals component. Used in signal amplification switches for Digital circuits and logic gates  ---  * Inverter logic circuit  --- ## Integrated circuits contains huge number of transistors and logic circuits   --- ## Wires and connectors  --- ## Boards * Bread board  --- ## Printed circuit board (PCB)   --- ## Measurement Instruments * multi-meter  --- ## function generator To generate signal waveforms  --- ## oscilloscope To measure and plot signals  --- ## Signal Varying voltage over time  --- ## Sampling or Digitalization * World is continuos or analog * limited memory to store signal continuously * Sample analog signal get representation of it.  --- ## Applications  --- ## Arduino Programming * Arduino is programmed using C++ language. * Equipped with essential built in functions * Handle simple interfacing with electronic devices --- ## Variables * Variables in C/C++ have different data types ```c int myVariable; //Define a variable myVariable with type int ``` * array is a group of values ```c int a[10]; //Array of 10 integers ``` --- ## Constants * Predefined variables * Example ```c++ #define HIGH 1 #define LOW 0 ``` --- ### Functions * subroutine that encapsulate some calculations * Builtin functions ```c //Setting mode of the pin INPUT or OUTPUT pinMode(pin, mode); //Write a value on the pin digitalWrite(pin); //Read value of an analog pin analogRead(pin); delay(ms); ``` * User defined functions * [type] [name]\(parameters\) ```c int add(int x, int y) { int z = x + y; return z; } ``` --- ### Control structures * Branching due to a condition * if * if, else * switch , case example ```c const int ledPin = 13; // choose the pin for the LED const int inputPin = 2; // choose the input pin (for a pushbutton) void setup() { pinMode(ledPin, OUTPUT); // declare LED pin as output pinMode(inputPin, INPUT); // declare pushbutton pin as input } void loop(){ int val = digitalRead(inputPin); // read input value if (val == HIGH) // check if the input is HIGH { // do this if val is HIGH digitalWrite(ledPin, HIGH); // turn LED on if switch is pressed } else { // else do this if val is not HIGH digitalWrite(ledPin, LOW); // turn LED off } } ``` --- ### Looping * for loop : for defined number of Instrumentations * while loop : based on condition example ```c void setup() { Serial.begin(9600);} void loop(){ Serial.println("for(int i=0; i < 4; i++)"); for(int i=0; i < 4; i++) { Serial.println(i); } } ``` --- ### Classes User defined type contains members, methods, functions Example ```c++ class MyClass { public: MuClass(int pin); void method1(); void method2(); private: int member1; }; ``` Accessing members and methods using . operator Example ```c++ // Print is a method in class Serial Serial.print(); ``` --- ## Library A library is code was written by someone and we will use it (Re inventing the wheel ) To use library ```c //Include header file of the library #include
``` --- ## Markdown Documentation ### Headers * Headers \# Header1 \## Header2 \### Header 3 For organizing your thoughts to main point with sub-points and so on. --- ## Links You can make hyperlink \!\[link](google.com) or just put the link if no hyperlink www.google.com **Example** visit [this](https://en.wikipedia.org/wiki/Markdown) for more details. --- ## Images \!\[\]\(imagename) image must be in the same folder or directory and must be uploaded with the md file **Example**  --- ## List \* item 1 \* item 2 \* item 3 Or 1\. Item 1 2\. Item 2 --- ## Code snippets \```c++ \#include \
int main() { std::cout << "Hello, World!" << std::endl; } \``` Lets see it ```c++ #include
int main() { std::cout << "Hello, World!" << std::endl; } ``` --- ## Useful links [Markdown Tutorials](https://www.markdowntutorial.com/)