Wednesday 26 June 2013

Controlling LED brightness using potentiometer and arduino

I was doing experiments with my Arduino today and this was one of them. I have commented the code well so it should be easy to understand. Here you go:
/*
SETUP
Connect led to analog pin 10, shorter end to ground.
Potentiometer setup:
(From left to right)
1. +5V
2. Analog pin 0 (A0)
3. Ground
*/

//Set LED pin to analog pin 10.
const int led_pin = 10;
//Set potentio meter pin to analog pin 0 (A0).
const int pot_met = 0;

void setup(){
  //Set led_pin to be the output.
  pinMode(led_pin,OUTPUT);
  //Initiate serial (optional).
  Serial.begin(9600);
}

void loop(){
  //Use the readPotentioMeterBrightness method to read brightness value.
  int sensor_val = readPotentioMeterBrightness();
  //Output the value to serial (optional).
  Serial.println(sensor_val);
  //Set LED brightness to value that we acquired from potentiometer.
  analogWrite(led_pin,sensor_val);
  //Pause for 250 ms.
  delay(250);
}

int readPotentioMeterBrightness(){
  //Read analog input and store value in integer variable val
  int val = analogRead(pot_met);
  //Adjust the value to be in range 0 to 255.
  val = map(val,0,1023,0,255);
  //Ensure value is between 0 and 255. 
  val = constrain(val,0,255);
  //Return value
  return val;
}

Thursday 20 June 2013

Copying symbolic links (UNIX/Linux)

At some point, you might come across a situation where you have some files and a bunch of symlinks (symbolic links) in a folder and you wish to copy the data that is pointed at by the symlinks and not just blank links. If you are using Redhat Enterprise Linux, this should automatically happen when you call the cp command. However, on UNIX platforms or Linux distributions, this is not the case by default. In those cases, you will have to issue the following command:

cp -L {file(s)} {destination folder}

The -L option in cp command forces it to follow (dereference) symlinks and copy the data that is pointed at by the symlink.

In case you do not want to follow symlinks, you can issue the following command instead:

cp -P {file(s)} {destination folder} 

Wednesday 19 June 2013

Mounting ISO images on linux

So I learnt this today and decided to share it with you guys. If you have an iso image and want to mount it on Linux, simply execute the following command in terminal:

sudo mount -o loop mydisk.iso myfoldername

So in my case, I had iso file called 2012photos.iso on my desktop and I wanted to mount it on folder called 2012pics which was on Desktop as well. I executed:

sudo mount -o loop /home/manthan/Desktop/2012photos.iso /home/manthan/Desktop/2012pics

Sunday 16 June 2013

The application was unable to start correctly (0xc000007b)

So I found this error when I started Lotus Notes this morning. After looking through some forums, I found that I needed to re-install Microsoft Visual C++ 2010 (Redistributable) from here.

This error is usually caused by C:\Windows\System32\MSVCR100.dll being corrupted. Reinstalling VC++  fixes it.